• Wanting to display one random posts from each category on my home page, below is what I have but I get the feeling it could be improved. Is there a way to make this into one loop that encompasses all categories?

    Another thing is I cant seem to get it to line up horizontaly, it seems to stagger on top of each other, also pasted my css for that div class.

    <!--archivos aleatorios-->
    <div class="rand-posts">
        <?php
    $args = array( 'numberposts' => 1, 'category' => '1' , 'orderby' => 'rand' );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><br /></a>Editorial / <?php the_title(); ?>
    <?php endforeach; ?>
    
        <?php
    $args = array( 'numberposts' => 1, 'category' => '3' , 'orderby' => 'rand' );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><br /></a>Retratos / <?php the_title(); ?>
    <?php endforeach; ?>
    
        <?php
    $args = array( 'numberposts' => 1, 'category' => '4' , 'orderby' => 'rand' );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><br /></a>Comida / <?php the_title(); ?>
    <?php endforeach; ?>
    
        <?php
    $args = array( 'numberposts' => 1, 'category' => '5' , 'orderby' => 'rand' );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><br /></a>Personal / <?php the_title(); ?>
    <?php endforeach; ?>
    
    <br /></div>

    The div class rand-posts

    .rand-posts {
    	width: 200px;
    	margin: 0;
    	padding: 0;
    	float: left;
    	clear: none;
    }
  • The topic ‘rand posts from each category’ is closed to new replies.