好的,这应该可以,你想要什么:
// Fetch all posts in the current post\'s (main) category
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => -1,
\'cat\' => array_shift(get_the_category())->cat_ID,
);
$query = new WP_Query($args);
// The index of the current post in its (main) category
$X = 1;
$id = get_the_ID();
foreach ($query->posts as $cat_post)
if ($id != $cat_post->ID)
$X++;
else
break;
// The number of posts in the current post\'s (main) category
$Y = $query->found_posts;
// Now, display what we got...
echo $X.\'/\'.$Y;
发生了什么事
我们取
all 当前(主要)类别的帖子,按发布日期排序。这样,我们已经拥有了该类别的职位总数。然后我们遍历这些帖子并增加一个计数器变量来跟踪当前帖子的索引。最后,我们在某处显示这些数字。