Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Wordpress - navigation sub-menu question

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
LezlyPrime
Asked:
LezlyPrime
  • 3
  • 2
1 Solution
 
Jason C. LevineNo oneCommented:
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
 
LezlyPrimeAuthor Commented:
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
 
Jason C. LevineNo oneCommented:
>> 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
 
LezlyPrimeAuthor Commented:
Just saw an issue with my Jewelry section & moved it all in one level.
0
 
LezlyPrimeAuthor Commented:
Apologies! Been working on a VB project & finally got back to WP. Thanks! The menu system in the theme worked beautifully!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now