• Hi everybody,

    I’m using the following code to display the 4 recent posts on the main page:

    <!-- Recent Blog Posts -->
        <?php
        //get post type ==> regular posts
            global $post;
            $args = array(
                'post_type' =>'post',
                'numberposts' => '4'
            );
            $blog_posts = get_posts($args);
        ?>
        <?php if($blog_posts) { ?>
            <section id="home-posts" class="clearfix">
                <h2 class="heading"><span><?php if(!empty($options['recent_work_text'])) { echo $options['recent_news_text']; } else { _e('Die neuesten Rezensionen','adapt'); }?></span></h2>
                <?php
                $count=0;
                foreach($blog_posts as $post) : setup_postdata($post);
                $count++;
                //get portfolio thumbnail
                $feat_img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'grid-thumb');
                ?>
    
                <article class="home-entry <?php if($count == '4') { echo 'remove-margin'; } if($count == '3') { echo ' responsive-clear'; } ?>">
                	<?php if ($feat_img) {  ?>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="nodec"><div class="caption"><img src="<?php echo $feat_img[0]; ?>" height="$feat_img[2]" width="$feat_img[1]" alt="<?php echo the_title(); ?>"><figcaption><?php the_date(); ?></figcaption></div></a>
                    <?php } ?>
                    <div class="home-entry-description">
    <h2 class="main"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo the_title(); ?></a>		</h2>
    			<i style="letter-spacing: 1px;">von <?php the_category(' '); ?></i>
                    </div>
                    <!-- /home-entry-description -->
                </article>
                <!-- /home-entry-->
                <?php
                if($count == '4') { echo '<div class="clear"></div>'; $count=0; }
                endforeach; ?>
            </section>
            <!-- /home-posts -->
        <?php } ?>

    Is there any way to alter that code in order to show 4 random posts excluding the recent 4 ones from that random selection?

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • <?php
    query_posts(array('orderby' => 'rand', 'showposts' => 1));
    if (have_posts()) :
    while (have_posts()) : the_post(); ?>
    
    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
    
    <?php the_content(); ?>
    
    <?php endwhile;
    endif; ?>

    Source: Link

Viewing 1 replies (of 1 total)

The topic ‘Random posts on homepage’ is closed to new replies.