I’m using the following php code on a page to show 10 posts per page from a single category.
function my_page_of_posts5() {
if (is_page('10')) {
$custom_loop = new WP_Query('posts_per_page=10&cat=9');
echo '<div class="my-archives"><ul class="archive-list">';
if ( $custom_loop->have_posts() ) :
while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
echo '<li><a class="archive-link" href="'
. get_permalink() . '">'
. get_the_title()
. '</a> <span class="my-comment-count">( ';
comments_number('0', '1', '%');
echo ' )</span></li>';
the_excerpt();
endwhile;
wp_reset_query();
endif;
echo '</ul></div>';
}
}
add_action('thesis_hook_after_content','my_page_of_posts5');
I’m using Thesis WordPress Theme Framework.
I want to display pagination after these posts on the page.
What code shall I put there to show the pagination?
I’ve tried using the WP-Paginate plugin and putting the wp-paginate(); function on the page but it doesn’t work fine.
Need another way to sort it out.
Without knowing more about what the exact behavior of your query is when you attempt to use
wp_paginate
, the best I can suggest is adding'paged=' . get_query_var( 'paged' )
to yourWP_Query
args, comme ça:Once you add that, wp_paginate might work for you.
Give it a shot!
UPDATE
Ok, from the start:
paged
query varposts_nav_link
to get the necessary navYour whole snippet should work like so:
Try using this code instead, replace it what you have now.
It adds a pagination function I always use, no need for an extra plugin. Easy to customize.
You may try adding this pagination code at the end of the code in your example:
The code works in archive and category pages of normal free themes, but the one you are using is not free and is not open source, so it’s hard to predict the result.
I think the posts quantity should be removed:
The reason is the number of posts per page in WP is configured in the Reading Settings. Placing a quantity in the query might be blocking the pagination. Needless to say, there must be more than 10 posts for pagination to work.
Good luck!
There is a Two possible Solutions :
(i). Solution #1 :
i wish you will think that wp-pagenavi is the best solution here. And it is too easy to integrate it in Thesis theme. As a Thesis theme user you are using thesis openhook plugin already.
Now just follow the steps to add pagenavi in Thesis theme.
<?php cr_pagenavi(); ?>
(ii). Solution #2 :
1. First of all I installed a plugin which is Simple Pagination (and its literally simple to use). If youâre using thesis, copy and paste this code in thesis_hook_after_content and hit save.
2. Go to your custom_functions.php and paste this code to remove the Previous and Next post
3. Check out your new pagination on your homepage and customize it to any style you want.