3

here is my issue.

I am currently in a post (so in single.php). I got the only category that this post is in by using:

$category = get_the_category()[0];

Now, what I would like to be able to know is the current position of that post in that category and I need to be able to retrieve that position without searching through all pages of the category (for performances reasons).

E.g: Let`s say my post is the 14th most recent post in its category, I want to get that value (14) so that I can then calculate on which category page it would be (knowing how many posts are displayed by page)

Thanks

4

1 回答 1

0

如果您提前知道帖子/页面的数量,则可以使用 SQL 来执行此操作。

假设你想做 10 个帖子/页。

SELECT * FROM articles WHERE category_id = :categoryID LIMIT 0, 10;

这将为您提供给定类别中的前 10 篇文章。如果您看到第二页的文章,您只需修改LIMIT

于 2013-09-15T20:11:36.973 回答