我该如何调用其他具有与当前帖子标题匹配的标记的帖子?例如,如果当前的帖子标题为“负鼠”,我希望所有贴有“负鼠”标签的帖子中的挑逗者显示在页面底部。
列出与当前帖子标题相同类别的帖子
2 个回复
SO网友:Ryan B
首先,您需要获取当前类别,然后获取帖子。所以,试试看
<ul>
<?php
global $post;
$category = get_the_category($post->ID);
$args = array( \'numberposts\' => -1, \'offset\'=> 1, \'category\' => $category );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
SO网友:Sam
$title_tagged_posts_query = new WP_Query( array(
\'tag\' => strtolower( get_the_title() )
) );
while ( $title_tagged_posts_query->have_posts() ) : $title_tagged_posts_query->the_post();
//Output whatever you want here.
endwhile;
结束