WordPress 3.x Page Navigation Error with inFocus Theme: Revisited

Steve March 22 Blogging , , with 0 and 0
Home/Blogging/WordPress 3.x Page Navigation Error with inFocus Theme: Revisited

Shortly after the release of WordPress 3 I offered a solution to broken page navigation conceivably caused by upgrading from version 2. Recently, in an attempt to fix a long-standing and seemingly unrelated issue, page navigation reared its head once more.

These instructions are only applicable for versions of inFocus up to and including v1.6

A detailed explanation and solution to the original issue can be found here. In short, the fix was to replace this code block in the file wp-content/themes/infocus/lib/includes/template-blog.php:

<?php
$exclude_blog_cats = preg_replace("!(\d)+!","-${0}$0", $blog_excludecats);
$query_string = "cat=".$exclude_blog_cats."&paged=$paged";
query_posts($query_string);
$counter=0;
?>

 

… with this, which tested the version of WordPress being used:

<?php
if ( (int)substr(get_bloginfo ('version'),0, stripos(get_bloginfo ('version'),'.')) < 3 ) { // WordPress 2.x or lower
	$paged = $paged ? $paged : 1;
} else { // WordPress 3.x or higher
	$paged = $page ? $page : 1;
}
$exclude_blog_cats = preg_replace("!(\d)+!","-${0}$0", $blog_excludecats);
$query_string = "cat=".$exclude_blog_cats."&paged=$paged";
query_posts($query_string);
$counter=0;
?>

 

Having used this fix for some 18 months it transpires that it’s only needed when using WordPress 3.x if blog posts are displayed on the front page i.e. in WordPress admin A static page is selected in Reading Settings > Front page displays. Changing this setting to Your latest posts breaks page navigation yet again.

Heres’s the revised code which only uses the $page variable when using WordPress 3.x and blog posts are displayed on the front page. Otherwise $paged is used.

<?php
if ( ( (int)substr(get_bloginfo ('version'),0, stripos(get_bloginfo ('version'),'.')) >= 3 ) && ( $show_on_front == 'page' ) && ( $page_on_front == $blog_page ) ) {
	// WordPress 3 or higher and blog posts displayed on front page
	$paged = $page ? $page : 1;
} else { 
	// WordPress 2.x or lower
	$paged = $paged ? $paged : 1;
}
$exclude_blog_cats = preg_replace("!(\d)+!","-${0}$0", $blog_excludecats);
$query_string = "cat=".$exclude_blog_cats."&paged=$paged";
query_posts($query_string);
$counter=0;
?>

About the Author

A native Brit exiled in Japan, Steve spends too much of his time struggling with the Japanese language, dreaming of Fish & Chips and writing the occasional blog post he hopes others will find helpful.

Add comment

©Tech Otaku 2009 - 2017