Welcome

Heartdrops is a website containing a personal blog, resources & website reviews. It is owned by me, Georgina. I'm 19 years old and I live in Australia.
Plug: Thistudio, Rachelisms, Lovestrings

Search

Updates

Links

WordPress Tutorial: Recently Updated Posts/Pages

Instead of manually showing what you’ve recently updated in WordPress, or having to widgetize your sidebar, you can use a simple code.

This tutorial will show you how you can use a simple piece of code to show both your recently updated posts and pages, a bit like this:

recently updated

The Code

The best place to put this code is in your sidebar or footer, where you have other website statistics and such.

<?php
$today = current_time('mysql', 1);
$howMany = 5; //Number of posts you want to display
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<h2><?php _e("Recently Updated"); ?></h2>
<ul>
<?php
foreach ($recentposts as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
the_title();
echo '</a></li>';
}
?>
</ul>
<?php endif; ?>

Customising

The parts in bold are the ones you can edit.

You do not need to place the posts/pages in a bulleted list. They can be numbered if you like, or you can just use a <br /> after each post.

The comment number need not be in curly brackets; these can also be displayed how you like.

The number 5 is the number of posts that are displayed. Edit to your liking.

Stylesheet and CSS

You might need to change the margin and padding of your lists if you want to place the code in your sidebar. There might be too much padding (by default) so we can use an id to deal with this. We must change <ul> to <ul id="recent">. This assigns an id for that element.

<h2>Recently Updated Posts/Pages</h2>
<ul id="recent">
...
</ul>

Next we must specify this element with CSS. The following goes in our stylesheet:

#recent {
list-style-image:url('image URL');
margin-left:0px;
padding-left:9px;
}

Adjusting the padding on the left hand side will shift the list as far from the side as you wish.

© Georgina Luhur, Heartdrops.org. 2007-2010, unless otherwise stated. Site Map | top ↑ | A part of Georgie.nu