• Resolved gashface

    (@gashface)


    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!

Viewing 1 replies (of 1 total)
  • Thread Starter gashface

    (@gashface)

    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();
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Get random posts from current category.’ is closed to new replies.