• I have a div, in which i was to show titles of recent posts, any idea of what the code will be like? prob show latest 5 posts if that helps? Cheers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Or use this code:-

    // GET POSTS
    		$r = new WP_Query(array('showposts' => $show, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
    		if ($r->have_posts()) :
    ?>
    		<?php echo $before_widget; ?>
    			<?php echo $before_title . $title . $after_title; ?>
    			<ul>
    			<?php  while ($r->have_posts()) : $r->the_post(); ?>
    			<li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
    			<?php endwhile; ?>
    			</ul>	
    
    <?php
    		// echo widget closing tag
    		echo $after_widget;
    
    		wp_reset_query();  // Restore global post data stomped by the_post().
    		endif;

    oh, and $show is the number of posts to be showed.

    Do $show = 5, and it will show 5 most recent posts.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress php code for recent posts?’ is closed to new replies.