I’m using the walker class below, but I can’t make it work with custom posts.
class Zwp_Walker_Nav_Menu_Dynamic extends Walker_Nav_Menu {
function end_el(&$output, $item, $depth) {
global $wp_query;
global $post;
$thePostID = $post->ID;
$subposts = get_posts( 'numberposts=10&cat=' . $item->object_id );
if ( $subposts ) {
$output .= ' <ul class="';
if ( $item->object_id == $post->ID && 100 == 101) { $output .= ' sub-menu-current'; } else { $output .= ' sub-menu'; }
$output .= ' sub-menu-item-'.$item->object_id.'">
';
foreach( $subposts as $post ) :
setup_postdata( $post );
$output .= '<li';
if ( is_single() && $wp_query->post->ID == $post->ID ) {
$output .= ' class="current"';
}
$output .= '><a href="'. get_permalink( $post->ID ) .'">' . get_the_title( $post->ID ) . '</a></li>
';
endforeach;
$output .= '</ul>
';
}
}
}
I tried to change the get_posts query, but I get strange results. (Probably because the ID is missing)
$subposts = get_posts( 'numberposts=10&post_type=portfolio_work' );
The result:
Design »
Project 1
Project 2
Photography »
Project 1
Project 2
About »
Project 1
Project 2
This is how it should look like:
Design »
Project 1
Photography »
Project 2
About
100 == 101
in youif
statement (always false)$subposts = get_posts( 'numberposts=10&post_type=portfolio_work&cat=' . $item->object_id );