WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help with Random Posts via Category Not quite working! (5 posts)

  1. MouseUK
    Member
    Posted 1 year ago #

    Hi,

    I'll I'm trying to do is to get 6 random posts pulled out of the "feature" category at random and display their featured picture (little 100x100px) image in a box on the right side of my site.

    I have it mostly working if I remove "orderby=rand" it shows all 6 images in the right hand box of the latest 6 featured posts but I also want it to display older posts from the category hence trying to get it to randomise it.

    When I add the orderby=rand I get it randomly picking out older posts which is good but it also randomly displays between 1 and 6 posts instead of 6 random ones and I have no idea why.

    <?php query_posts('category_name=feature&showposts=6&orderby=rand'); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    Any ideas/help would be grateful.
    Thanks
    MouseUK

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    it also randomly displays between 1 and 6 posts instead of 6 random ones

    do all of those 'feature' category posts have a featured image aka post thumbnail?

  3. MouseUK
    Member
    Posted 1 year ago #

    Yes, they all have a featured image.

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    ideally, can you post a link to your site with the problem showing?

    does the 'feature' category have sub categories?

    what is the full code of your extra loop?

  5. MouseUK
    Member
    Posted 1 year ago #

    I've found it, you were right with your original post, I thought I had all the ones in the feature category set-up with an image.
    But thought I'd go through them all again to double check and 2 were missing :D

    Sorted now, Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic