0

我只想显示该类别的第一篇文章的评论。

例子;

类别
- 帖子 1(2 条评论)
- 帖子 2(1 条评论)
- 帖子 3(5 条评论)

如果我正在阅读Post 2Post 3,我应该看到Post 1 的 2 条评论

如何从模板文件中对此进行编码?

感谢您的帮助。

4

1 回答 1

0

你只需要像这样使用 WP_query ( http://codex.wordpress.org/Class_Reference/WP_Query ):

$args = array(
'cat' => 'catnumber',
'post_count' => '1'
 );

$query = new WP_Query( $args );

该查询将返回您想要的类别的最后一篇文章。然后你只需要在你的循环中使用函数 get_comments :http: //codex.wordpress.org/Function_Reference/get_comments

于 2013-02-11T07:28:22.423 回答