WordPress.org

Ready to get started?Download WordPress

Forums

Show 3 random posts from last 8 posts of a category. (2 posts)

  1. lydiamunoz
    Member
    Posted 3 years ago #

    Hi! I don't know how can i do something:

    If my code is:

    <?php
    query_posts('cat=3&posts_per_page=3&orderby=rand');
    while (have_posts ()): the_post();
    echo "

  2. ID) . "'>";
    the_title();
    echo '
  3. ';
    endwhile;
    ?>

    I have getting all the posts of category 3. But my question is. Can i get only last 8 posts of category 3? I don't want 3 of all the posts. I want 3 of last 8 posts. How can i do it?

    Maybe my english is very bad. I hope you understand what i want to say. Thanks!

  • lydiamunoz
    Member
    Posted 3 years ago #

    Sorry, i didn't know i have to mark code button:

    <?php
    			 define('WP_USE_THEMES', false);
    			 require_once($_SERVER['DOCUMENT_ROOT'] . '/contenidos/wp-blog-header.php');
    			query_posts('cat=3&posts_per_page=3&orderby=rand');
    			 while (have_posts ()): the_post();
    			 echo "<li><a href='" . get_permalink($post->ID) . "'>";
    			 the_title();
    			 echo '</a></li>';
    			 endwhile;
    			?>
  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags