• Resolved drummergirl

    (@drummergirl)


    I’m building an e-commerce shop and I’m using posts to feature products. Each post is listed in multiple categories and also tagged. What I’d like to do is display the categories in the sidebar and when the user clicks, it loads the category page (customized to only display the thumbnail image for each post in a grid format). I’d like for this grid to display the products randomly each time so older products aren’t lost in the sea of new items. The user can then page through to see the rest as some categories will contain hundreds of product designs. Is that possible with a category page?

    I know how to do this with query_posts by specifying a category and random post, but I don’t want to create a separate category template page for each category because the categories get added on the fly as new products are added. I also want the same thing for tag pages and for the search results.

    Can this be done? If so, can someone point me in the right direction for coding it. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • the following might work (not intensively tested):

    instead:

    <?php if( have_posts() ) : while (have_posts()) : the_post(); ?>

    try:

    <?php if( have_posts() ) : global $query_string; query_posts($query_string . '&orderby=rand'); while (have_posts()) : the_post(); ?>

    Thread Starter drummergirl

    (@drummergirl)

    This worked perfectly, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Randomize posts in a category?’ is closed to new replies.