Solved

Wordpress - navigation sub-menu question

Posted on 2012-04-02
5
415 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Like there are many different versions of Wordpress, there are also a handful of related side projects WordPress users should be familiar with.   All of these projects are open source and GPL licensed, which means there are few restrictions to us…
How to create your own WordPress Theme Before I begin with the theme design tutorial, I would like to give you the basics of what is required to make a WordPress Theme. The most basic WordPress theme only requires 2 files: a style.css file and an…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

685 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