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 (Jul 31, 2007)
One other thing I just noticed is if you’re using Ultimate Tag Warrior, then you’ll want to change this line
if ($wp_query->is_home) {
to
if (is_home() && !is_tag()) {
Azhag (Aug 01, 2007)
Thanks a lot for this trick, I’ve been searching for a way to put these kind of link to HemingwayEx !
ovidiu (Aug 01, 2007)
hello, I have read your posts on hemingwayEx and have a question: I love this theme but it doesn’t play nice with IE6, tehre are even a few posts on his support forum and I jsut noticed your site play really well with IE6 so maybe you can help us out in that support forum?
here is the link: http://nalinmakar.com/forum/
TechZilo (Aug 03, 2007)
You are live and kicking on WordPress too….cool. Keep up the good work.
And cool theme :D
ovidiu (Aug 13, 2007)
any chance you will help us get it working with IE too?
moggy (Aug 14, 2007)
Not sure what you mean. This has nothing in it that’s browser-specific.
ovidiu (Aug 14, 2007)
thx for your post in the forum I linked above, I just noticed, its possible you did nothing to the theme, as the author stated the above sidebar menu will work fine with IE 6+7 if you use the hemingway modules and not widgets :-( sorry to have bothered you…
Sleeper (Aug 30, 2007)
Hi! First of all, thanks for that tricks. Now, I want to ask you how can I change the color to the top row (the purple one!!) that is orange at the original theme.
Thanks!
Joe (Sep 19, 2007)
Is it true the slidebar absolutely won’t function in IE6/7 if you are using widgets? i’d like to keep flickr and twitter widgets nestled in there, but as it stands, IE will open but won’t close the slidebar. is there a known work-around to tweak the template so it’s compatible with IE — when using widgets?
Joe (Sep 19, 2007)
moggy, sorry my previous comment isn’t really in the appropriate thread. i just read your comment to nalin. are you aware whether circumventing script.aculo.us in that manner helps with IE buggyness? if so, i’ll likely try out your jQuery suggestions.
thanks a bunch.
moggy (Sep 26, 2007)
@ Joe
I’ve never ran into those issues myself. Do either the twitter or flickr widgets use javascript? Specifically, prototype or scriptaculous? If so, there might be a conflict there & switching over to jQuery would probably help. I can’t really say for sure, however.
J. Lynne (Oct 07, 2007)
Thank you so much! This makes so much sense too once I look at it.
emanuele (Jan 07, 2008)
hi moggy, your idea its fantastic!!!
but i show 1 problem (to this theme) and 1 question (to your plugin)…
the problem is the video in home page.. if i post the video in home with "Embedded Video with Link" plugin, don’t appear nothing.. (only the code)..
why?????
the question is: if i want change the buttons "previous entries" and "next entries" with 2 images, How should I do?
thanx!!!!!
moggy (Jan 08, 2008)
@emanuele
I’m not familiar with the “Embedded Video with Link” plugin.
If you want to use images for the next/previous links then you should just be able to insert some HTML as the text you pass into the functions:
<?php next_posts_link(‘<img src=”prev.gif” alt=”« Previous Entries” />’) ?>
<?php previous_posts_link(‘<img src=”next.gif” alt=”Next Entries »” />’) ?>
emanuele (Jan 09, 2008)
ok great moggy!!!
so… now i know how to do… but the "embedded video with link" plugin remains a problem… i’ll try to resolve it soon…
thanx for all
Bradley (Jun 05, 2008)
Hi! I’m delighted that you were able to paginate the HemingwayEx
theme but this method does not work for Wordpress 2.5.1 and
HemingwayEx 1.1. :( I’m not a PHP wizard so any help is
appreciated.
moggy (Jun 05, 2008)
It looks like HemingwayEx 1.1 made some changes. To get this to work with 1.1, make the following changes to the aforementioned steps.
Step 1: Comment out the following lines from the plugin.
//global $hemingwayEx;
//$category_id = $hemingwayEx->get_asides_category_id();
Step 2: In the index.php file, comment out the following line (located towards the top of the file).
//query_posts(’showposts=2′);
Bradley (Jun 05, 2008)
@moggy WOW! Simply amazing! Many thanks to you! Such a wonderful
addition to an elegant theme.
mugz (Jun 06, 2008)
hey moggy, ever tried to put more than 2 posts on the front page
with hemmingway ex? im having trouble, if you change the number to
4, well, see for yourself http://www.techgutter.com
moggy (Jun 07, 2008)
@mugz
Briefly, yeah. The CSS isn’t setup to let you do that by default. I decided I’d rather be able to page the home page, so I never really looked into what CSS changes would need to be made.
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