我想显示一个帖子的实际数量+所有喜欢:“第3号,共19个帖子”。
我尝试过-它显示了所有的帖子,但我不知道如何显示当前的帖子编号。
No. {POST NUMER} of <?php $count_posts = wp_count_posts(); echo $count_posts->publish; ?> Posts
发布于 2014-09-13 16:13:18
如果这是在wp_query
中,您可以执行以下操作:
echo $wp_query->current_post+1;
来源:https://wordpress.stackexchange.com/questions/20789/print-current-post-index-number-within-loop
如果没有,我认为你需要解释一下Wordpress你所说的“帖子编号”到底是什么意思--也就是说,它应该以什么标准来计算。为此,您可能需要使用与您相关的$args (例如post_status => publish
)来重建wp_query
。尽管可能有一些我不知道的内置方式。
编辑
这是未经测试的:
/** Your current post id*/
$curr_id = get_the_ID();
/** Your posts query */
$args = ('post_status' => 'publish', 'orderby' => 'this depends on you'); // ... and all other args you would need
$posts = get_posts($args);
$posts_count = count($posts);
for ($i=0;$i<$posts_count;$i++) {
if ($posts[$i]->ID === $curr_id) {
$current_post_num = $i;
break;
}
}
echo "No. $current_post_num of $posts_count Posts";
一些小贴士:
https://stackoverflow.com/questions/25820833
复制相似问题