(re) Enabling the past

May 26, 2008 by jerome

sangbleu.png

A few days ago, I had to modify the SangBleu WordPress theme for Maxime. Maxime finally wanted to give access to the recent archives pages. The SangBleu theme has been built on top of Naked Wordpress Theme; Naked is a drastically simplified theme with just the strict minimum DOM architecture. As such it is very easy to develop your own CSS - which is not the case with the standard Kubricks theme: too many intricated elements in the DOM structure, producing a super huge and complex stylesheet.

You can download the Naked theme from http://bealers.com/wordpress-naked/; it is definitely a must-have if you’re going to develop some small project and need flexibility as well as simplicity.

The problem I faced was a bit silly: the posts_nav_link was not behaving correctly - I changed at some point the MySql bits form the origianl theme: the Loop was not a standard one, but a simple MySql request on the database.

$querystr = "	SELECT wposts.*
    FROM $wpdb->posts AS wposts
    WHERE wposts.post_status = 'publish'
    AND wposts.post_type='post'
    ORDER BY wposts.post_date DESC LIMIT 0,20
 ";

$pageposts = $wpdb->get_results($querystr, OBJECT);

if ($pageposts): ?>
<ol id="posts">
				setup_postdata($post);
[...]
			endforeach;
[...]
endif;</ol>

This MySql bit does not query any paged items. To manage to get the paging back, I had to re-modify the way the theme is requesting the posts from the database. In order to have the pagination for past posts enabled, I simply did a copy/paste from the Kubricks theme. So, I replaced the above by the following:


if (have_posts()) :
while (have_posts()) : the_post();
[...]
endwhile;
endif;

In Wordpress you can control the pagination on a page with multiple posts (like index.php) using the template tag: posts_nav_link. This tag takes 3 parameters, the first one being the string inserted at the beginning, the last two parameters being quite obvious…
posts_nav_link(’ · ‘, ‘previous page’, ‘next page’)
In order for it to work, you need to have a Loop on the page which is going to query the posts using a paged information.

On a single post page, you can also use the next_post_link() and previous_post_link() to display links to the individual next/previous post.

* http://codex.wordpress.org/Template_Tags/posts_nav_link


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment