I recently ran into a situation when developing a new WordPress theme in which I need to offset a second column of posts by the number in the main posts column. This second column is to be a column of short snippets, older posts if you will.
Obviously the situation at hand is quite simple, you would run your query posts loop and then use offset to skip over the number of posts in your main article column. However in this situation, being that it will be a theme which any number of people with different settings might be using, I had to find a way to make this a bit more intuitive.
Bascically what I want to be able to do here is offset this second column by the number of posts a given user has selected in the Settings>Reading section of WordPress.
The simple solution would look something like this.
<?php
function mytheme_column_query() {
$num = get_option('posts_per_page');
?>
<div id="left-column">
<?php $recent = new WP_Query("showposts=4&offset=$num"); while($recent->have_posts()) : $recent->the_post();?>
/*-- Run Loop --*/
</div>
<?php
}
What this does. First we use get_option('posts_per_page') to retrieve the posts per page setting, which is set in the WordPress admin under the reading settings. The second thing we do is set up our query using offset = $num. Obviously in this particular query I am also looking to only pull 4 posts which is the reason for showposts=4. Fairly straighforward and simple.
Now in my particular situation I also needed to account for a featured post which will not be included in either loop. So with that in mind I added this:
$offset = $num+1;
<?php $recent = new WP_Query("showposts=4&offset=$offset"); while($recent->have_posts()) : $recent->the_post();?>
That’s it, feel free to add your questions and comments/additions below. Oh and this does mean that I will have a new theme coming shortly!