remsen
remsen

Reputation: 35

wp_nav_menu list posts from category?

I'm using the custom menus in WP 3.3.1. I can drag a category into a menu and it creates a link to an archive page of all the posts form that category. Is there something I can put in the functions that forces a list of all the posts from that category instead?

So, I would end up with something like:

<ul>
    <li><a>Category</a>
        <!-- expander -->
        <ul>
            <li><a>Psot 1</a></li>
            <li><a>Post 2</a></li>
            <li><a>Post 3</a></li>
        </ul>
    </li>
</ul>

Upvotes: 1

Views: 2139

Answers (2)

Max
Max

Reputation: 26

You can make walker class in functions.php

This is exaple in the end of walker with posts entry:

        $item_output = $args->before;
    $item_output .= '<a'. $attributes .'>';
    $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    $term_list = wp_get_post_terms($item->object_id, 'products_brand', array("fields" => "names"));
    if(!empty($term_list[0])){ $item_output .= $indent . '('.$term_list[0].')'; }
    $item_output .= '</a>';
    $item_output .= $args->after;

    if ($item->object=='category') {$cat = $item->object_id;
    $item_output .='<ul>';
    global $post;
    $args = array( 'numberposts' => 5, 'offset'=> 0, 'category' => $cat );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post);
    $title=get_the_title(); $permalink=get_permalink(); 
    $item_output .= '<li><a href="'.$permalink.'">'.$title.'</a></li>';
    endforeach;
    $item_output .= '</ul>';
    }

Upvotes: 1

Eric Oliver
Eric Oliver

Reputation: 89

You can manually add posts to the menu by enabling "posts" in the screen options (click "screen options" in the upper right-hand corner and then tick the "posts" box -- you'll now see a box with all your posts in it).

Unfortunately, though, it sounds like you want the menu to update automatically with all your posts for a certain category. I'm not aware of any way to do that with custom menus. I think you'd have to get your hands dirty and actually modify the theme to get that working...

Upvotes: 0

Related Questions