Solved

Wordpress - navigation sub-menu question

Posted on 2012-04-02
5
395 Views
Last Modified: 2012-07-04
Wordpress - navigation sub-menu question

I'm fairly new to Wordpress but not to PHP. I'm having issues loading my navigation with sub-menus. I do not want to use a plug-in or the dashboard.

Here is the menu structure:

Home
About
Products
      Rings
            Gold
            Silver
      Pendants
      For Men      
Services
      Technical
      Administrative      
Contact Us

Screen shots:

Home, About, & Contact Us pages - these look fine:

homePageNavigation
Products page - messed up:

productsPageMenu
Services page - messed up:

servicesPageMenu

Below is the code from Codex that I used.

<?php
$allPages = wp_list_pages();
    if ($allPages) {
        foreach($allPages as $onePage) {
            if(!$post->post_parent){
                // will display the subpages of this top level page
                $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
            } else {
                // diplays only the subpages of parent level
                $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
            }

            if($post->ancestors) {
		// now you can get the the top ID of this page
		// wp is putting the ids DESC, thats why the top level ID is the last one
		$ancestors = end($post->ancestors);
		$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
		// you will always get the whole subpages list
            }

            if ($children) {
                echo '<ul><li>';
        	echo $children;
        	echo '</li></ul>';
            }
        }
    }
?>

Open in new window


I did some testing in the conditional section of code & no matter what I did, the results never changed. So on a whim, I deleted everything except for this line of code:

$allPages = wp_list_pages();

And the results remained the same.

I've looked at tons of other code, on forums & in articles. None of the code presented includes anything like the line above & when I implement any of these solutions into my project, nothing shows in the navigation section. I don't get an error, but there is no navigation menu.

For example, in this codex code from wp_list_pages:

<?php
  if($post->post_parent)
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  else
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  if ($children) { ?>
  <ul>
  <?php echo $children; ?>
  </ul>
  <?php } ?>

Open in new window

 
I get nothing. No errors, but no menu, either.

What am I missing here?

Thank you in advance for any suggestions or help.
0
Comment
Question by:LezlyPrime
  • 3
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 250 total points
Comment Utility
It's a CSS issue, but in reading:

"I do not want to use a plug-in or the dashboard."

Why do you not want to use the built-in Custom Menus?  It vastly simplifies the process of creating and maintaining navigation?
0
 

Author Comment

by:LezlyPrime
Comment Utility
Because I couldn't get that to work either! ~lol. Here's the code I used in my header template:

<?php wp_nav_menu( array( 'theme_location' => 'mbmMenu' ) ); ?>

...where mbmMenu is the name of my Menu in the dashboard. The output looks exactly the same as the screen shots above.

Here is a screen shot of my menu settings in the dashboard.

dashboard settings
If it's a CSS issue, then I've seen something about that but didn't read it closely. Thanks.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
>> If it's a CSS issue, then I've seen something about that but didn't read it closely. Thanks.

It's definitely a CSS issue.  What's going on in both scenarios (using wp_list_pages() or Custom Menu) is that you don't have the correct CSS to display drop-down items so the submenus display funky.  The home page is probably using wp_list_pages() but only looking for top-level pages and that's why it displays ok.  

Usually this happens because you select an older theme and the theme dev hasn't properly set the CSS for the newer WordPress functionality.  Are you married to the theme?
0
 

Author Comment

by:LezlyPrime
Comment Utility
Just saw an issue with my Jewelry section & moved it all in one level.
0
 

Author Closing Comment

by:LezlyPrime
Comment Utility
Apologies! Been working on a VB project & finally got back to WP. Thanks! The menu system in the theme worked beautifully!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Now that you've installed WordPress 2.9 (http://www.experts-exchange.com/articles/Web_Development/Blogs/WordPress/WordPress-2-9-What-to-Expect-When-Upgrading-to-WordPress-2-9.html?) on your site, you need to install some plugins to get the most out …
Transferring a wordpress site from a host or local dev server to another host can be a pain. So I've included my steps on how I have accomplished this task. Steps include an assumption that you have Cpanel access or Ftp access.. If you do not hav…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now