开发者

wordpress show random posts while paged

I have 700 artworks (custom post type) and I want to break them in pages, but they have to be开发者_开发技巧 in random places each time.

The problem is that when I use

'paged'=>$paged, 'posts_per_page' => 60, 'orderby'=>rand

each page repositions the post and you can find the same post on ex. 2nd and 7th page.

Is there a way to first random the posts and then break them into pages? Or randomise posts per session, or per ip?


My assumption would be that 'orderby' => rand simply selects a random post one at a time, so each time it has the option to display a post with the option rand it simply chooses one from your database at random, independent of the rest of the page and posts.

A possible solution to your problem is to take a completely different approach all together.

Every time your homepage is visited you could call a PHP script that would randomly generate a list of unique numbers, once for every post (in your case, 0-700). You could than modify your database (either by adding an extra column to the posts row, or modify/append an existing one) with said random number. You could than set it to order by the new/modified column, thus ensuring the the posts were randomized for every visitor to your page, but that it never displays the same post twice. However...you would need to test it, I've never modified the 'orderby' variable in the code itself, since I've never had the need to.

You could also try doing something similar as the above, but instead change the orderby option in the backend (as opposed to the code), assuming your theme gives you the option (which I imagine it would).

I hope that solves your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜