0

I'm trying to figure out how to write a conditional before I call paginate_links() in my home.php and that will work in other custom page templates.

After reading about pagination in custom loops from How to fix pagination for custom loops? I'm calling my pagination before the reset query.

I've figured out how to get my entered post count in Settings > Reading > Blog pages show at most with get_option('posts_per_page') and I've learned how to call total count of posts in a category from Count how many posts in category, based on result display link or not but when I run:

$total_posts        = $query->post_count;
$per_page_default    = get_option('posts_per_page');
if ($total_posts > $per_page_default) :
    // other code
endif;

it works on the first page only but when I go to any page after the first it disappears. Why is that? How can I get pagination to only show when total post count in a particular category in a custom page template and that I can use in home.php work when the posts exceed the set quantity?

0

Total number of pages is $query->found_posts divided by $per_page_default. If the current page number is less than that amount, there are more pages.

post_count isn't the total amount of posts, as the answer on the question you linked states, it's the total number of posts on that single page only. That's not going to tell you anything except maybe that you're on the last page if the number happens to be less than total per page, but will fail if the total is divisible without remainder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.