?
Solved

Wordpress - navigation sub-menu question

Posted on 2012-04-02
5
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 1000 total points
ID: 37798773
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
ID: 37802963
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
ID: 37803030
>> 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
ID: 37803076
Just saw an issue with my Jewelry section & moved it all in one level.
0
 

Author Closing Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

WordPress has made it easy to create scalable sites based on their powerful CMS, but as great as WordPress is, there are some SEO issues that haven’t been addressed out of the box.  Fortunately these problems can be solved with a few plugins.  The f…
Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses

764 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