你可以create a new query 对于自定义帖子类型中的所有帖子,然后遍历每个帖子并将其与当前帖子id匹配,以确定其位置。
// save current id to match later
$current_project_id = $post->ID;
$args = array(
\'post_type\' => \'project\',
\'posts_per_page\' => -1
);
$all_projects = new WP_Query( $args );
while( $all_projects->have_posts() ) : $all_projects->the_post();
// simple \'if\' test to find the current post in the loop
// note that current_post starts at zero, which is why we add 1 to it.
// you can also output the_title, the_permalink, thumbnails, etc..
if( $post->ID == $current_project_id ):
echo "project " . ( $all_projects->current_post + 1 ) . " of " . $all_projects->post_count;
endif;
endwhile;
这里需要注意的是,您正在每个页面上加载所有项目,如果您有很多项目,这可能会很昂贵。您可能希望设置一些缓存以保持速度。