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
}
moggy (Aug 15, 2008)
An updated version of this plugin is located here
Pingback (Nov 25, 2008)
HemingwayEx in french • Archives du site • Duretz sur le Net !
Chris (Dec 11, 2008)
Hey moggy – thanks for the help man. I’ve followed you instructions
and everything works great. Just the last step – places the (
<?php next_posts_link('« Previous Entries') ?><?php previous_posts_link('Next Entries »') ?>)code… – I assume it’s in the index.php of the hemmingway theme
that I put this, and then also, it then places the “next/previous”
links in weird palce on some pages….exactly where in the
index.php page should I insert the code? Thanks!
moggy (Dec 12, 2008)
Hey Chris — here’s what I’m currently using:
<?php if (function_exists('custom_hem_home_query')): ?><div class="clear"></div>
<div class="navigation" style="text-align:center;">
<?php
if ($paged == 0) $curr_paged = 1;
else $curr_paged = $paged;
$prev_paged = $curr_paged - 1;
$next_paged = $curr_paged + 1;
?>
<?php previous_posts_link('«« '); ?>
<?php echo 'Page ' . $curr_paged; ?>
<?php next_posts_link(' »»'); ?>
</div>
<?php endif; ?>
I have it inside the HemingwayEx index.php file just below the loop
chaospilot (Dec 30, 2008)
hi there. i would just like to ask what did you do in your RECENT
ENTRIES so that it would look like this: 06.15 HemingwayEx
Widgets please get back to me :P ill appreciate the help. thanks
Pingback (Jan 28, 2009)
Aisleone.net: Hemingway Ex template and … « Performa project updates