Support » Fixing WordPress » How to add code after certain navigation items?

  • Resolved Epro


    Hello all,

    Site in question is here

    Basically I want to detect if a page uses my page template called “Vehicle Showcase” so I can add custom code after to make a dropdown containing a list of previous and current vehicles. These are all custom post types.

    I’d also like to do this for the classifieds and blog page.

    [No bumping, thank you.]

Viewing 7 replies - 1 through 7 (of 7 total)

    You can use the is_page_template() function to test for you specific page template and then display content conditionally.

    How would I fire that while WP is generating my navigation with <?php wp_list_pages(‘title_li=’); ?> ?

    Hmm…so you’re trying to make the main navigation different depending on the page template? You can filter wp_list_pages with add_filter('wp_list_pages', 'your_wp_list_pages_filter_function_call'); but I think the code to sub a dropdown into the navigation could get messy.

    My suggestion would be to see if your theme supports menus and then you could simply create 2 different menus; use is_page_template() to determine which menu to call; use <?php wp_nav_menu( array( 'theme_location' => 'menu1' ) ); ?> to call the appropriate menu.


    This is a custom theme I made, but learning how to add support for menus couldn’t hurt I guess.

    I would really recommend it, it’s pretty easy. I was slow to adopt the new custom menus but it makes managing them so much easier.

    I had a hack solution in mind, where I would generate the sub-menu after the navigation, and then use javascript to relocate it to where I wanted it originally, but I’d rather do it the clean way.

    I ended up extending the walker class, if anyone wants any information on how I did this, I can explain further.

    Here’s the end result:

    class Dropdowns extends Walker_page {   
    function end_el(&$output, $item, $depth=0, $args=array()) {
        if ($item -> ID == 55) { //checks if the page id is the list item I want to make my dropdown under
             $vehicles = query_posts('post_type=vehicles'); //my custom post that I want to dropdown
             if ($vehicles) { //check for no entries
                //code for drop downs go here
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to add code after certain navigation items?’ is closed to new replies.