• Resolved micasuh

    (@micasuh)


    I am trying to make a menu based on Sons of Suckerfish (https://htmldog.com/articles/suckerfish/). I’d like to have a two level menu of pages and subpages.
    https://codex.www.ads-software.com/Template_Tags/wp_list_pages

    Here’s a basic line of code output I’m shooting for:

    <div id="pagenav">
    	<ul>
    		<li><a href="https://website.com">Home</a></li>
    		<li class="page_item page-item-2 current_page_item"><a href="about/">About</a>
    			<ul>
    				<li class="page_item page-item-5"><a href="https://website.com/location/" title="Location">Location</a></li>
    <li class="page_item page-item-6"><a href="https://https://website.com/contact/" title="Contact">Contact</a></li>
    <li class="page_item page-item-16"><a href="https://https://website.com/staff/" title="Staff">Staff</a></li>
    			</ul>
    		</li>
    	</ul>
    </div>

    Obviously, there are more list items, but this is a basic example.

    I’m not sure What the proper code would be. I’d like the whole thing to be dynamic, but I’m aware that the first level must be static since it’s not easily possible to have two levels of dynamic lists.

    Thus, here’s my PHP code:

    <div id="pagenav">
    	<ul>
    		<li<?php if(!is_page() ) { ?> class="current_page_item"<?php } ?>><a href="<?php bloginfo('home'); ?>">Home</a></li>
    		<li<?php if(!is_page() ) { ?> class="current_page_item"<?php } ?>><a href="about/">About</a>
    			<ul>
    				<?php wp_list_pages('include=16,5,6&sort_column=menu_order&depth=1&title_li='); ?>
    			</ul>
    		</li>
    	</ul>
    </div>

    When I am in the About page, when the above PHP code generates into HTML, it does not insert the following into the About list item:

    class="page_item page-item-2 current_page_item"

    Can anyone give me some ideas of what to do?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Here’s the PHP that works for me:

    <?php if (is_page()) { $highlight = "page_item"; } else {$highlight = "page_item current_page_item"; } ?>
    <ul>
    <li class="<?php echo $highlight; ?>"><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wp_list_pages('sort_column=menu_order&title_li=') ?>
    </ul>
    Thread Starter micasuh

    (@micasuh)

    drmanry, that code works for only one level of menus. It would wonderfully but doesn’t completely serve my needs. I need two levels of menus, one which is a sublevel of the root level.

    Thanks for anyone who can give me other suggestions.

    micasuh,

    The code works for multiple levels of menus. In your code, you have specified depth=1, which will show only top-level pages. The default is depth=0, which is the assigned value if not specified. This causes all pages to be listed, including sub-pages.

    It works.

    Thread Starter micasuh

    (@micasuh)

    drmanry,

    Please forgive my ignorance as I’m a novice with PHP and WordPress code.

    Could you possibly help me learn how to make this work? With all the pages I have created, I want 4 particular pages to be the top-level and about 10 other certain pages to be sublevels of one of these top 4 pages for the dropdown menu.

    What I do not understand is how to specify top levels and sublevels for my needs, nor has any WordPress documentation indicated what I would need to do this.

    I appreciate your help!

    Thread Starter micasuh

    (@micasuh)

    Well, after a little frustration, error, and then trial, I figured everything out. So, for those who come to this later seeking the answer to my question, here’s what I found out.

    Parent – Using this part of the pages, giving certain pages a parent page, helps to form the sub-levels of the parent. So, in my first example above, Location, Contact, and Staff all should have a parent page of About.

    Sort order – I wanted all the parent levels and sub-levels to be ordered a certain way. In the php, this attribute enables that to happen:
    sort_column=menu_order
    In order for these orders to appear correctly, one must assign a numerical order in the part of the page called Order and assign values numerically beginning with 1.

    What I couldn’t understand at first is how wp_list_pages was able to list all top-level and sub-level menus correctly but hopefully my explanation made sense why it’s possible.

    Thanks again, drmanry!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘dynamic drop down menu (wp_list_pages)’ is closed to new replies.