WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add code after certain navigation items? (8 posts)

  1. Epro
    Member
    Posted 1 year ago #

    Hello all,

    Site in question is here http://cars.evanparsons.net/

    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.]

  2. Brett Shumaker
    Member
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/is_page_template

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

  3. Epro
    Member
    Posted 1 year ago #

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

  4. Brett Shumaker
    Member
    Posted 1 year ago #

    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.

    References:
    http://codex.wordpress.org/Navigation_Menus
    http://codex.wordpress.org/Function_Reference/wp_nav_menu

  5. Epro
    Member
    Posted 1 year ago #

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

  6. Brett Shumaker
    Member
    Posted 1 year ago #

    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.

  7. Epro
    Member
    Posted 1 year ago #

    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.

  8. Epro
    Member
    Posted 1 year ago #

    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: http://cars.evanparsons.net

    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
             }
    
        }
    }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic