0

I have a Worpdress Blog and I would like to display post randomly into all the category pages.

For example, when I go here http://www.iltrentinodeibambini.it/category/rubriche/lo-sai-che/ I want to see the post randomly ordered, not sorted by date.

I've tried to find a Plugin that could help me, but I didn't find anything. How can I do? Is there any PHP code that I can put before the loop in my "page.php" file?

I'm using Throne Theme with WP 4.0 (http://themeforest.net/item/throne-personal-blogmagazine-wordpress-theme/8134834).

Thanks Filippo

1
  • 2
    randomizing the order is fairly simple via the pre_get_posts hook, however, the task is complicated by the fact that this alone will give you truly random order, meaning you could see posts repeated on subsequent pages. to solve this you need to seed the randomization, like in this answer.
    – Milo
    Commented Nov 25, 2014 at 20:29

1 Answer 1

-1

You can use the following line of code in your category.php file for Random posts.

<ul>
 <?php $posts = get_posts('orderby=rand&numberposts=5'); 
    foreach($posts as $post) { ?>
     <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php  the_title(); ?></a>
     </li>
<?php } ?>
</ul>
</li>
1
  • Won't work. This will break what your category page is all about. Custom queries don't solve problems, they create more problems Commented Nov 26, 2014 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.