WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get random posts from current category. (2 posts)

  1. gashface
    Member
    Posted 2 years ago #

    Hi there, I am trying to get random posts from the current category of a post page. Like a sort of related posts using categories. I want these as thumbnails within a grid, which works fine... that is the counter part of my code (which needs to be in there)

    Here is the start of the loop

    <?php
    $c = 1; //init counter
    $bpr = 3; //boxes per row
    foreach(get_the_category() as $category)
    {
      $cat = $category->cat_ID;
    }
    query_posts('cat=' . $cat . '&showposts=3&orderby=rand');
    if(have_posts()) :
    while(have_posts()) :
    the_post();
    ?>

    At the moment it only shows one post and fails to retrieve anymore posts from within the category. any help?

    thanks!

  2. gashface
    Member
    Posted 2 years ago #

    Nevermind I have fixed it. for anybody else who is curious:

    <?php
    $c = 1; //init counter
    $bpr = 3; //boxes per row
    foreach(get_the_category() as $category)
    {
      $cat = $category->cat_ID;
    }
    query_posts('cat=.$cat.&showposts=3&orderby=rand');
    if(have_posts()) :
    while(have_posts()) :
    the_post();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic