WordPress.org

Ready to get started?Download WordPress

Forums

Random and recent post widget (2 posts)

  1. t_virus
    Member
    Posted 2 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
    Member
    Posted 2 years ago #

    try this:

    <!--- Random Post -->
    			<li id="randompost" class="widget-container">
                <h3 class="widget-title"><?php _e( 'A Random Post', 'twentyten' ); ?></h3>
                 <ul>
                 <?php
                   $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; ?>
                </ul></li>

Topic Closed

This topic has been closed to new replies.

About this Topic