使用API函数是一种选择,在我看来,通常更可取。作为计数,归档页面上的编号不是问题,这涉及到如何在单个帖子的视图中进行编号。这不是现成的代码,只是一个示例性的大纲:
$current_posts_id = get_the_ID();
$wp_query_obj = new WP_Query(
[
//other conditions to determine order
//use the same as for the archive page, otherwise the numbering differs
//use parameter fields to get an array of
//keys numerically indexed, with value post id
\'fields\' => \'ids\'
]
);
//get the numerically array of post ids into its own variable
$wp_query_posts_array = $wp_query_obj->posts;
//search array by value, which is the post id, and return corresponding key, numeric index
$wp_query_posts_array_index = array_search( $current_posts_id, $wp_query_posts_array );
//the array index starts with 0, add one for the issue numbering
$current_posts_issue_number = $wp_query_posts_array_index + 1;
注意:如果您想即时获取发行号,当然可以这样做。一般来说,如果您希望或必须更频繁地使用问题编号,或者希望在可以使用问题编号的地方进行查询,我可能会引入一个post meta来存储问题编号。但这只是我对可能必要的代码、数据结构设计选择的想法。