WordPress:类别帖子计数
我正在尝试找出一种获取特定类别中帖子数量的方法,然后在帖子本身上显示帖子编号。为了更好地解释,我正在在我的网站上创建一个投资组合部分,而不是将帖子ID显示为增量(因为我的ID没有顺序),我宁愿以某种方式计算我的投资组合类别中的帖子并显示增量。下图。
I am trying to figure out a way to get the number of posts in a specific category, then display the posts number on the post itself. To better explain, I'm creating a portfolio section on my site and rather than displaying the posts id as the increment (because my id's are not in order), I'd rather somehow count the posts in my portfolio category and display the increment. Example picture below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用
$ WP_QUERY
并在循环中获取发布索引。请参阅下面的示例。current_post
将在循环中获取该帖子的索引。索引从0开始,因此我们将其添加到它,因此它将开始计数为1。在
functions.php
:在循环中,使用我们上面创建的函数:
You would need to use
$wp_query
and get the post index in the loop. See the below example.current_post
will get the index of that post in the loop. The index starts at 0 so we add one to it so it will start counting at 1.In
functions.php
:In the loop, use the function we created above: