Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am taking over a site and we are making a sister site to it, but the problem is that the navigation was set up for the other site - so I'm having an issue getting the navigation to link to the pages. What it is doing is using a filter of some sort... so when I try to click a link on the nav bar nothing happens but an empty drop down menu displays. We have no need for child pages on this project so I need help figuring out how to edit the filter so that parent pages act as links rather than "menu titles" if you will.

here's my code:

<?php 

                //add_filter ('wp_list_pages', 'formatNavList');
                $myPages = wp_list_pages(array('title_li' =>'', 'depth' =>1, 'sort_column' => 'menu_order, post_title', 'echo' =>0, )); 

                $templateDir = get_bloginfo("template_directory");
                $pattern1 = "/<li.*?>.*?<a.*?>(.*?)<\/a>/is";
                $replString1 = "<li class='navButton' >$1
                <div class='dropdown1Col' >
                    <img class='dropdown1ColTop' src='$templateDir/images/bgGraphics/DropDownNav_1ColTop_200x30.png'  />
                    <div>
                        <img class='dropdown1ColMid' src='$templateDir/images/bgGraphics/DropDownNav_1ColMid_Stretch.png' />";

                $pattern2 = "/(<\/li>\s*?<li[^>]*navButton.*?>)/is";
                $replString2 = "            <p class='clearFloat' />
                                    </div>
                                <img class='dropdown1ColBtm' src='$templateDir/images/bgGraphics/DropDownNav_1ColBtm_200x30.png'  />
                            </div>$1";


                $pattern3 = "/(<\/li>\s*?)$/is";
                $replString3 = "            <p class='clearFloat' />
                                    </div>
                                <img class='dropdown1ColBtm' src='$templateDir/images/bgGraphics/DropDownNav_1ColBtm_200x30.png'  />
                            </div>";

                $menu = explode('<li ', $myPages);
                $sub = 0;
                $i = 0;
                $id = array();

                foreach ($menu as $key => $val) {

                    $match = $matches = 0;

                    if ($sub == 0){
                        $id[] = $key;
                        $pos = strpos($val,'<a');
                        $text = preg_replace($pattern1, $replString1, "<li alt='$sub' $val");
                        $output .= $text;
                    }else{
                        $output .= "<li alt='$sub' $val";
                    }
                    if (preg_match_all("/(<ul class='children'>)/",$val,$match,PREG_PATTERN_ORDER)){
                        $sub = $sub + count($match[0]);
                    }else if (preg_match_all("/(<\/ul>)/",$val,$matches,PREG_PATTERN_ORDER)){
                        $sub = $sub - count($matches[0]);
                    };
                    $i++;
                    if($i==3){$i=0;};

                }
                $output = preg_replace($pattern2, $replString2, $output);
                $output = preg_replace($pattern3, $replString3, $output);

                echo $output;
            ?>

any help would be greatly appreciated! Thank you in advance!

share|improve this question

2 Answers 2

I would recommend using the WP_Nav Menu for your site. To use this feature, just add this in place of your current nav:

<?php
    add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
    array(
        'primary-menu' => __( 'Main Menu' ),
        'secondary-menu' => __( 'Secondary Menu' ),
        'tertiary-menu' => __( 'Tertiary Menu' )
        )
    );
}
?>

Then you can use this to display the navigation in your template files:

<div id="menu">
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?><!-- End Navigation -->
</div><!-- End #menu-->

With the code above you can use up to 3 menu's in different locations. To add another, just change the 'primary-menu' in the example above to one of the other 3 listed in the functions.php file. You can now go to the WP-Admin>Appearance>Menu's and create your nav menu and add the pages/posts, or categories/tags to the menu and make it as many levels deep as you wish.

share|improve this answer

If you want to stick with using a page menu (though I would strongly recommend @Jeremy Jared's solution of using custom Nav Menus), replace all of your above code with this:

wp_list_pages( array( 'title_li' =>'', 'depth' =>1, 'sort_column' => 'menu_order, post_title' ) );

Then, use CSS to apply whatever layout/style you need.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.