Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Fix Broken Blog Pagination WordPress

  • SOLVED

I am using a WP theme called WP-Solid but the theme developer has now vanished and the customer has only just asked to have the blog feature of the website activated.

The blog is inserted onto a page using a shortcode and posts per page is set in the shortcode:

Eg: [blog posts=3]

The navigation appears at the bottom of the page but clicking any of the buttons only returns a blank page with the title 'Blog' (The page title for the blog page should be 'news').

You can see the page and problem here:

[[LINK href="http://jeaniusconsulting.com/news/"]]http://jeaniusconsulting.com/news/[[/LINK]]

Here is the code from the shortcodes template file that relates to blog posts:


function ewf_sc_blog( $atts, $content = null ){
global $post;
$src = null;

extract(shortcode_atts(array(
"posts" => 2,
"categ_include" => null,
"categ_exclude" => null,
"posts_exclude" => null,
"layout" => "single",
"height" => "auto",
"width" => "auto",
"date" => "true",
"info" => "true",
"nav" => "true",
"style" => null
), $atts));

$position = array('odd', 'even');
global $more;

wp_reset_query();

$paged = get_query_var('page') ? get_query_var('page') : 0;
if ($paged == 0){
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
}

$wp_query_blog = new WP_Query(array( 'post_type' => 'post', 'posts_per_page' => $posts, 'paged' =>$paged ));
$count = 0;

/*
echo '<br/>Paged:'.$paged;
echo '<br/>Page:'.get_query_var('page');
echo '<pre>';
print_r($wp_query_blog);
echo '</pre>';
*/

while ($wp_query_blog->have_posts()) : $wp_query_blog->the_post();
$count++;
$pair = $count % 2;


$post_class = get_post_class();
$post_class_fin = null;

foreach($post_class as $key=> $ctclass){
$post_class_fin.= ' '.$ctclass;
}

$src .= '<div class="blog-post '.$position[$pair].' fixed '.$post_class_fin.'">';

$image_id = get_post_thumbnail_id($post->ID);
if ($image_id>0){
$src .= '<div class="col-220">';
$thumb_details = wp_get_attachment_image_src( $image_id ,'column-220-auto');
$src .= '<img src="'.$thumb_details[0].'" alt="'.get_the_title().'"/>';
$src .= '</div>';

$src .= '<div class="col-460 last">';
}

$src .= '<h3><a href="' . get_permalink() . '" rel="bookmark">'.get_the_title($post->ID).'</a></h3>' ;

if ($info == "true"){
$src .= '<p>'.__('Posted by', EWF_SETUP_THEME_DOMAIN).': <strong>'.get_the_author().'</strong> | '.__('Posted on',EWF_SETUP_THEME_DOMAIN).': <strong>'.get_the_time('F jS, Y').'</strong> | <a href="'.get_comments_link().'">'.get_comments_number().' '.__('Comments', EWF_SETUP_THEME_DOMAIN).'</a></p>';
}

$more = false;
$src .= do_shortcode(get_the_content(__('Read More', EWF_SETUP_THEME_DOMAIN)));
$more = true;

if ($image_id>0){
$src .= '</div>';
}

$src .= '</div>';


if ($wp_query_blog->post_count > $count){
$src .= '<div class="hr"></div>';
}

if ($wp_query_blog->post_count == $count && $nav == "true"){
$src .= '<div class="hr"></div>';
}

endwhile;

if ($nav == "true"){
$src .= ewf_sc_blog_navigation($posts, $wp_query_blog);
}
return $src;
}


Any takers?

Answers (4)

2013-11-12

Sébastien | French WordpressDesigner answers:

send me your theme folder please, i check this
[email protected]

I have try the theme. There is no problem. Have you more than 3 posts in your blog administration ?

You use WordPress 3.7.1... maybe the problem comes from this


Sébastien | French WordpressDesigner comments:

i have try with wp 3.7.1 and that works...


Sébastien | French WordpressDesigner comments:

ok
the problem seems to come from the name of the page
if i use "news" that doesn't work
change the name and (slug probably) by another title please


Sébastien | French WordpressDesigner comments:

in your theme "news" is a custom post type. So you can't use this name for a page :-/


Sam Cranwell comments:

Ah ha! You got it :)

Just tried it with the word 'Test' and it works.... unfortunately the customer wants the blog to be called 'News'...

I'm guessing its clashing with the custom post type that is called 'news' somehow.

Could the shortcode functions be edited to make it work?


Sam Cranwell comments:

I don't need the 'News' custom post type...


Sébastien | French WordpressDesigner comments:

the custom post type "news" is created by the line 95 in the file _admin/functions-type-news.php


Sébastien | French WordpressDesigner comments:

just comment the function ewf_register_type_news() at the line 95 in the file _admin/functions-type-news.php


Sébastien | French WordpressDesigner comments:

or replace 'news' by 'news2' (for example) in the file _admin/functions-type-news.php at this lines

3
add_theme_support( 'post-thumbnails', array( 'post', 'page', 'slide', 'project', 'news' ) );

20
$query = array( 'post_type' => 'news', 'posts_per_page' => $items, 'order'=>$order, 'orderby'=>'ID' );

64
$query = array( 'post_type' => 'news', 'posts_per_page' => $items, 'paged' => $paged, 'order'=>$order, 'orderby'=>'ID' );

95
register_post_type('news',

99 + 100
'name' => __( 'News' ,EWF_SETUP_THEME_DOMAIN ),
'singular_name' => __( 'News' ,EWF_SETUP_THEME_DOMAIN ),

115
'slug' => 'news',


Sam Cranwell comments:

I can't find this line in _admin/functions-type-news.php

add_theme_support( 'post-thumbnails', array( 'post', 'page', 'slide', 'project', 'news' ) );


I changed all the other lines you suggested but it still doesn't work...


Sébastien | French WordpressDesigner comments:

sorry
this line is in the file _admin/functions-setup.php
line3


Sam Cranwell comments:

Found it - still doesn't work :(

Pagination now returns me to the site homepage...


Sam Cranwell comments:

Wait... just updated my permalinks and it now works!

Many thanks for all of your help.


Sébastien | French WordpressDesigner comments:

just refresh the permalink settings please

2013-11-12

Fahad Murtaza answers:

I am on it.


Fahad Murtaza comments:

Seems like there is nothing wrong with the code itself.

To do that go to Setttings » Reading and under the Front page displays option choose A static page

Below that, choose the page to be used as the front page. (Looks like you have done it already) and the page for your blog posts. For the second option, select the news page from the drop down. It should solve your problem.

If not, I can look into your settings if you could send me blog admin login though private message.

2013-11-12

Remy answers:

what is the code for the function "ewf_sc_blog_navigation"


Sam Cranwell comments:

Sorry - should have posted this:

function ewf_sc_blog_navigation($range = 4, $query){
$src_nav = null;
$max_page = null;

$class_current = 'current';

$current_page = $query->query_vars['paged'];
if ($current_page == 0) { $current_page = 1; }


// How much pages do we have?
if ( !$max_page ) {
$max_page = $query->max_num_pages;
}

$src_nav .= '<ul class="pagination fixed">';

// We need the pagination only if there are more than 1 page
if($max_page > 1){

$src_nav .= '<li><strong>'.__('Page ',EWF_SETUP_THEME_DOMAIN).$current_page.' of '.$max_page.'</strong></li>';

if(!$current_page){
$current_page = 1;
}
// On the first page, don't put the First page link
if($current_page != 1){
// $src_nav.= "<li><a href=" . get_pagenum_link(1) . "> First </a></li>";
}

// We need the sliding effect only if there are more pages than is the sliding range
if($max_page > $range){
// When closer to the beginning
if($current_page < $range){
for($i = 1; $i <= ($range + 1); $i++){

$src_nav.= "<li ";
if($i==$current_page) $src_nav.= "class='".$class_current."'";

$src_nav.= "><a href='" . get_pagenum_link($i) ."'";
$src_nav.= ">$i</a></li>";
}
}
// When closer to the end
elseif($current_page >= ($max_page - ceil(($range/2)))){
for($i = $max_page - $range; $i <= $max_page; $i++){
$src_nav.= "<li ";

if($i==$current_page) $src_nav.= "class='".$class_current."'";

$src_nav.= "><a href='" . get_pagenum_link($i) ."'";
$src_nav.= ">$i</a></li>";
}
}
// Somewhere in the middle
elseif($current_page >= $range && $current_page < ($max_page - ceil(($range/2)))){
for($i = ($current_page - ceil($range/2)); $i <= ($current_page + ceil(($range/2))); $i++){
$src_nav.= "<li ";

if($i==$current_page) $src_nav.= "class='".$class_current."'";

$src_nav.= "><a href='" . get_pagenum_link($i) ."'";
$src_nav.= ">$i</a></li>";
}
}
}
// Less pages than the range, no sliding effect needed
else{
for($i = 1; $i <= $max_page; $i++){
$src_nav.= "<li ";

if($i==$current_page) $src_nav.= "class='".$class_current."'";

$src_nav.= "><a href='" . get_pagenum_link($i) ."'";
$src_nav.= ">$i</a></li>";
}
}

// On the last page, don't put the Last page link
if($current_page != $max_page){
// $src_nav.= "<li><a href=" . get_pagenum_link($max_page) . "> Last </a></li>";
}
}

$src_nav .= '</ul>';


return $src_nav;
}

2013-11-12

phppoet answers:

Both the code you pasted seems incomplete . I have sent you a PM .

check it .

regards

correction: code is okay . look at my latest comment.


phppoet comments:

navigation links works okay on my localhost with all themes . both Code seems okay (ignore my previous comment) .

did you tried by changing permalinks or creating new page with shortcode and then select it as homepage like options ?

regards