我想按分类列出当前页面的兄弟页面。下面列出了当前页面的所有同级页面,但如何按分类术语进行查询?
if($post->post_parent):
$children =
wp_list_pages('depth=1&title_li=&child_of='.$post->post_parent.'&echo=0');
endif;
if ($children) {
// do something
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
}
发布于 2016-04-20 01:01:10
不能向wp_list_pages函数传递taxonomy
参数。为了满足您的需求,您可以使用wp_get_post_terms获取帖子分类,并使用[get_posts][2]
函数检索属于该类别的帖子。
发布于 2016-04-20 02:20:35
假设您已经在代码的另一部分中拥有了您想要的术语,您可以尝试这样做:
$siblingPages = get_posts(array(
'post_type' => 'page',
'tag' => $current_tag,
'post_parent' => $post->post_parent,
'post__not_in' => $post->ID
));
标记‘want
https://stackoverflow.com/questions/36724154
复制相似问题