Random and recent post widget (2 posts)

  1. t_virus
    Posted 4 years ago #

    Most of the themes have a sidebar widget with recent/polular and random posts widget. Those widgets show post thumbnails too
    Please if anyone could share the code. Also, i'm trying to avoid timthumb so please provide a code which does not use timthumb

    [No bumping, thank you.]

  2. Tara
    Volunteer Moderator
    Posted 4 years ago #

    try this:

    <!--- Random Post -->
    			<li id="randompost" class="widget-container">
                <h3 class="widget-title"><?php _e( 'A Random Post', 'twentyten' ); ?></h3>
                   $rand_posts = get_posts('numberposts=1&orderby=rand');
                  foreach( $rand_posts as $post ) :
                 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                <?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic