I just used max_num_pages in query get post in my site. And also use qTranslate-X plugin. It’s return double number page then can not use paginate_links function.
Any suggest to me resolve? Thank you.
]]>According to https://www.ads-software.com/support/topic/front-page-query_posts-limit-posts-only-on-first-page-1
I found that 5 posts from offset are not displayed on last page – they needs next page.
I have 408 published posts.
So $wp_query->max_num_pages = 41
.
But index.php is:
global $query_string;
$front_limit = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ( is_paged() ? ( ($paged - 2) * $posts_per_page + $front_limit ) : 0 );
$posts_per_page = get_option('posts_per_page');
$my_query = '&ignore_sticky_posts=1';
$my_query .= '&offset='.$offset;
$my_query .= '&paged='.$paged;
if ( !is_paged() ) :
$my_query .= '&posts_per_page='.$front_limit;
else :
$my_query .= '&posts_per_page='.$posts_per_page;
endif;
query_posts( $query_string . $my_query );
So on 41 pages I have 405 posts (41 pages limited to 410 posts, but front page takes only 5 posts and following pages have offset by those 5 taken from front page).
And 3 last posts are missing.
Correctly number of pages should be:
$front_limit = 5;
$total_posts = $wp_query->found_posts;
$posts_per_page = get_option('posts_per_page');
$total_pages = ceil( ( $total_posts - $front_limit ) / $posts_per_page ) + 1;
I have no problem to modify navigation to set max number of pages 42, but page 42 just no exists.
Temporarily I just used trick for last page (41):
if ( !is_paged() ) :
$my_query .= '&posts_per_page='.$front_limit;
else :
if ( $paged == $wp_query->max_num_pages ) $posts_per_page += $front_limit;
$my_query .= '&posts_per_page='.$posts_per_page;
endif;
So page 41 displays up to 15 posts (in my case 13).
But this is not satisfactory result. If someone have an idea, please let me know.
Note: fix for first page posts navigation is
$args = array_merge( $wp_query->query_vars, array( 'showposts' => get_option('posts_per_page')) );
query_posts( $args );
before call of "paginate_links"
Thanks in advance!
Greetings
$args = array('posts_per_page' => 7, 'paged' => $current_page, 'post_type' => 'post', 'suppress_filters' => false);
$postslist = get_posts( $args );
global $wp_query;
$totalpages = $wp_query->max_num_pages;
In this case, the value of $totalpages = 94 which is correct.
However, the visitors should also be able to select that they only want to see the posts which belong to a certain category. In that case, I add category to the arguments array like this:
$args = array('posts_per_page' => 7, 'paged' => $current_page,'category' => $category_id, 'post_type' => 'post', 'suppress_filters' => false);
The posts of the correct category are shown correct on my page, however
`global $wp_query;
$totalpages = $wp_query->max_num_pages;
stills gives me the result 94 pages, which is not correct because 94 pages is the correct amount of pages for all categories.
Can someone explain me how I can find the total number of pages when I query the posts of 1 category?
Thanks in advance
]]>This is a child theme of twentytwelve.
The page pulls four ‘location’ taxonomies into one page and displays the featured image with the post name in two columns. Just a light navigation page for a mobile theme. I could pull all nav and show all of the posts, but that would get download heavy.
Any insight would be appreciated.
<?php
//The Query - Pulls the 4 categories as planned.
//Currently totals 42 individuals.
//'posts_per_page' => -1, returns all 42, so the loop pulls everything properly.
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = new WP_Query();
$args->query( array(
'&paged='.$paged,
'post_type' => 'individuals',
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'home-location',
'terms' => array('new-york','new-jersey','connecticut'),
'field' => 'slug',
),
array(
'taxonomy' => 'visiting-location',
'terms' => array('new-york'),
'field' => 'slug',
),
),));
?>
<?php
// My loop - Puts the featured image and the post title (individuals names) into two columns. Works fine.
$col = 0;
$col_count = 2;
$cols = array();
//if($args->have_posts()) : - commented out. doesn't seem to make difference
while ( $args->have_posts() ) : $args->the_post();
if($col >= $col_count) $col = 0;
ob_start();
?>
<div class="post" id="post-'<?php the_ID(); ?>'">
<h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<div class="entry">
<?php
if ( has_post_thumbnail() ) {the_post_thumbnail( 'index-thumbnail' );
// the current post has a thumbnail
} else {
// the current post lacks a thumbnail
}
?>
</div>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
$cols[$col++] .= $output;
$count++; //one example had this. commenting out doesn't seem to make much difference
endwhile; // end of loop
//endif; - commented out. doesn't seem to make difference
wp_reset_query();
is_home(); // end of loop - is_home() seems irrelevant, but was suggested somewhere
?>
<div class="columns">
<?php
foreach($cols as $key => $col)
echo '<div class="column column' . $key . '">' . $col . '</div>';
?>
</div>
<?php
// Three different variations of suggested navs.
// One - This one adds page numbers to the nav. 1st page returns 10. 2nd page returns the next 10. 3rd and 4th pages error.
// the url in the link does site/home-location/new-york/ for 1st page. .../new-york/page/2/ for page 2 and .../new-york/page/2/page/3 for the non-working page 3.
if($args->max_num_pages>1){?>
<p class="pager">
<?php
for($i=1;$i<=$args->max_num_pages;$i++){?>
<a href="<?php echo get_category_link($category_id).'page/'.$i;?>" <?php echo ($paged==$i)? 'class="active"':'';?>><?php echo $i;?></a>
<?php
}
if($paged!=$args->max_num_pages){?>
<a href="<?php echo get_category_link($category_id).'page/'.$i;?>">Siguiente</a>
<?php } ?>
</p>
<?php } ?>
<?php
// Two - This one adds the traditional older/newer nav. 1st page returns 10. 2nd page returns the next 10. 3rd page errors.
// the url in the link does site/home-location/new-york/ for 1st page. .../new-york/page/2/ for page 2 and .../new-york/page/3/ for the non-working page 3.
?>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('? Older Entries', $args->max_num_pages) ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries ?', $args->max_num_pages) ?></div>
</div>
<?php
// Three - This one adds number navigation. Page 1 functions the same. All other pages return the same posts.
// the url comes in .../new-york/?page=(page num) exmp: ?page=3
if($args->max_num_pages>1){
if ($paged > 1) { ?>
<a href="<?php echo '?page=' . ($paged -1); //prev link ?>"><</a>
<?php
}
for($i=1;$i<=$args->max_num_pages;$i++){?>
<a href="<?php echo '?page=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a>
<?php
}
if($paged < $args->max_num_pages){?>
<a href="<?php echo '?page=' . ($paged + 1); //next link ?>">></a>
<?php
}
}?>
]]>global $wp_query;
$total_pages = $wp_query->max_num_pages;
var_dump($total_pages); exit;
I get:
int(0)
when there are like 15, 16 posts. so it should go 1 -> 16
I see other posts, that no one has responded to in regardes to this
]]>. This is the site so please check and help me.
index.php
https://pastebin.com/PQhf3cXB
I’m using wp_query to get a list of custom posts of a single taxonomy.
While I get the correct posts back, the $wp_query->max_num_pages value is incorrect (it returns the total number of pages based on the custom post type – without the taxonomy filter).
You can see the code I’m using here : https://pastebin.com/NBDDma2q (nothing special really). Can anyone reproduce the problem ? Not sure if I’m doing something wrong or if this is an actual bug.
Thanks,
gNesher
Normal post type.
The ‘grid’ custom post type.
Two problems using the following code:
1) I get 0 as maxPages (should be 3).
2) I’m missing the custom post part.
Many thanks for your time and help.
]]> Normal post type.
The ‘grid’ custom post type.
Two problems using the following code:
1) I get 0 as maxPages (should be 3). 2) I’m missing the custom post part.
[Code moderated as per the Forum Rules. Please use the pastebin]
Many thanks for your time and help.
]]>On my local windows apache server, the blog pages and the archives are not showing the next/prev posts, not matter how many posts I specify in the settings or how many posts I have.
I have re downloaded and installed wp 3.0 manually. Deactivated all plugins, reinstalled twentyten 1.0 in case it was that, but it appears to be theme independent and still happens when no plugins – this is happening to all themes.
I managed to track it down in includes>query.php to
‘found_posts’ being 0 (although posts are displaying and not_found is false)
which makes max_num_pages = 0, which means the “links” get skipped when loop.php checks it.
This is not happening on my remote servers (also on 3.0 and 2010 theme).
I have googled and tried checking the trac, but did not see anything that may explain or relate.
I have to leave this a bit and somehow test my new plugin without this, but it is concerning. I had some weird query post behavior too where ‘post_per_page’ = -1 did not appear to work and was wondering if it is related?
Anyone shed any light?
]]>