Forums

[resolved] Display random posts from featured category slideshow (5 posts)

  1. sofielyr
    Member
    Posted 2 years ago #

    Hi fellow wordpressers!

    I am trying to solve an issue with my featured category slideshow in wordpress. I want the featured to show five posts from the "featured" category (in the slideshow) in random order.

    This is the code that I have that displays five posts but always in the same order...

    <?php
    	$tmp_query = $wp_query;
    	query_posts('showposts=5&cat=' . get_cat_ID(dp_settings('featured')));	if (have_posts()) :
    	while (have_posts()) : the_post();
    	?>

    I want to add something that makes the five posts show in a totally random order...

    Hope you can help me!

  2. sofielyr
    Member
    Posted 2 years ago #

    Is there no-one who can help me with this? Please i beg you!!!

  3. Mark / t31os
    Moderator
    Posted 2 years ago #

    Sure, try this..

    <?php
    	$tmp_query = $wp_query;
    	query_posts( array( 'orderby' => 'rand' , 'posts_per_page' => 5 , 'category__in' => array( get_cat_ID(dp_settings('featured') ) ) ) );
    	if (have_posts()) :
    	while (have_posts()) : the_post();
    ?>
  4. sofielyr
    Member
    Posted 2 years ago #

    Yey!! Thanks so much!! It worked wonderfully!

  5. Mark / t31os
    Moderator
    Posted 1 year ago #

    You're welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic