Paging The HemingwayEx Home Page
By default, the HemingwayEx theme only shows 2 posts on the home page. This is all well & good except for the fact that you can’t use the paging (next & previous) links on your home page to show older posts as well.
If you want to get the paging links working, then here’s 3 steps to achieve that goal.
Step #1:
Create a new PHP file (you can do this easily with a simple text editor like Notepad). Name it custom_hem_home_query.php. Now copy & paste the following code into it.
<?php
/*
* Plugin Name: Custom HemingwayEx Home Query
* Plugin URI: http://moggy.laceous.com/2007/07/29/paging-the-hemingwayex-home-page/
* Description: Gives you the ability to use the paging links on your homepage
* Version: 0.1
* Author: Moggy
* Author URI: http://moggy.laceous.com
*/
add_filter('query_string', 'custom_hem_home_query');
function custom_hem_home_query($query_string) {
global $wp_query;
$wp_query->parse_query($query_string);
if ($wp_query->is_home) {
global $hemingwayEx;
$category_id = $hemingwayEx->get_asides_category_id();
if (is_null($category_id)) {
$query_string .= '&posts_per_page=2';
}
else {
$query_string .= '&posts_per_page=2&cat=-' . $category_id;
}
}
return $query_string;
}
?>
Save the file & upload it to your wp-content/plugins folder. When you’re ready… activate the plugin.
Step #2:
Now we have to remove the custom query from the wp-content/themes/hemingwayEx index.php file. Find the following code in the index.php file:
// Here is the call to only make two posts show up on the homepage REGARDLESS of your options in the control panel
$category_id = $hemingwayEx->get_asides_category_id();
is_null($category_id) ? query_posts('showposts=2') : query_posts('showposts=2&cat=-' . $category_id);
Simply comment out those lines so it looks like this:
// Here is the call to only make two posts show up on the homepage REGARDLESS of your options in the control panel
//$category_id = $hemingwayEx->get_asides_category_id();
//is_null($category_id) ? query_posts('showposts=2') : query_posts('showposts=2&cat=-' . $category_id);
Step #3:
Now you just need to add the paging links to your index.php file. Something like this should work:
<div class="navigation">
<?php next_posts_link('« Previous Entries') ?>
<?php previous_posts_link('Next Entries »') ?>
</div>
One final note:
You could also wrap the code from steps 2 & 3 with an if statement like the following if you want to be able to dynamically enable & disable the plugin.
if (function_exists('custom_hem_home_query')) {
// put code here
}

25 Comments
Jump to comment form | comments rss [?] | trackback uri [?]