我正在使用下面的walker类,但我无法将其用于自定义帖子。
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>
\';
}
}
}
我试图更改get\\u posts查询,但得到了奇怪的结果。(可能是因为缺少ID)
$subposts = get_posts( \'numberposts=10&post_type=portfolio_work\' );
结果:
Design »
Project 1
Project 2
Photography »
Project 1
Project 2
About »
Project 1
Project 2
它应该是这样的:
Design »
Project 1
Photography »
Project 2
About