WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Random Posts From Specific Category - with Custom Fields (2 posts)

  1. jillsays
    Member
    Posted 3 years ago #

    I'm trying to get wordpress to display random posts from a specific category, while using their Custom Field images.

    This is the code I am currently using. How can I fix that so it displays a random post instead of the most recent?

    <?php query_posts("showposts=6&category_name=PICS"); $i = 1; ?>
          	<?php while (have_posts()) : the_post(); ?>
    	<div class="clearfloat">
    	<?php $values = get_post_custom_values("Image");
    	if (isset($values[0])) { ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> 
    
    <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
    $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=150&h=115&zc=1&q=100"
    alt="<?php the_title(); ?>" class="center" width="150px" height="115px"  /></a>
    <a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
      <?php } ?>
    
          <?php endwhile; ?>
  2. David Gwyer
    Member
    Posted 3 years ago #

    Add the orderby=rand attribute to the query_posts function as follows:

    <?php query_posts("showposts=6&category_name=PICS&orderby=rand"); $i = 1; ?>
              <?php while (have_posts()) : the_post(); ?>
        <div class="clearfloat">
        <?php $values = get_post_custom_values("Image");
        if (isset($values[0])) { ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> 
    
    <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
    $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=150&h=115&zc=1&q=100"
    alt="<?php the_title(); ?>" class="center" width="150px" height="115px"  /></a>
    <a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
      <?php } ?>
    
          <?php endwhile; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic