Forums

How to display random posts of every category in category page of my site? (8 posts)

  1. pandasica
    Member
    Posted 1 year ago #

    I want to display random posts of every category in my site...for example if you go to category SPORT you should see all posts from that category randomly, if you go to category MUSIC you should see all posts from that category randomly etc etc...i know how to do that for index page but i cant figure out how to do that for category page....THANKS IN ADVANCE

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query

    Something like this in category.php before the loop [untested]:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $current_cat = get_query_var( 'cat' );
    $args = array(
    'orderby' => 'rand',
    'cat' => $current_cat,
    'paged' => $paged,
    );
    query_posts($args);
    ?>
  3. pandasica
    Member
    Posted 1 year ago #

    Thank you so much. i was looking for that. problem is solved!!!
    thank you again.

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    You're welcome. Glad you got it resolved.

  5. rajesh428
    Member
    Posted 1 year ago #

    I want to implement this using thesis theme

    Plz help me out

    thnx in advance

  6. supertouch
    Member
    Posted 1 year ago #

    Works fine with me as well. BUT: Would it also be possible to use the random loop only for a specific category?

  7. newsdevice
    Member
    Posted 1 year ago #

    @supertouch: sure, just use a conditional category tag

  8. supertouch
    Member
    Posted 1 year ago #

    Got it! you made my day :)

Topic Closed

This topic has been closed to new replies.

About this Topic