This in sidebar.php or in a Widget created with Otto’s PHP Code widget:
<?php
$posts=get_posts('post_type=post&showposts=3');
if ($posts) {
foreach($posts as $post) {
setup_postdata($post);
?>
<p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php }
}
?>
Thread Starter
girrl
(@girrl)
Thanks for this! I’m running into a problem though. I’m using Otto’s PHP code widget and pasted what you posted. It’s pulling the link for the page that I’m on…not my posts?
If I have both “Recent posts” and the PHP code widget added, then the PHP code pulls from my recent posts correctly. But I don’t need/want both of these widgets.
Any clue why it’s behaving like this?
This is better:
<?php
$args=array(
'showposts'=>3,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
?>