Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Montezuma Theme (http://forum.bytesforall.com/forumdisplay.php?f=53)
-   -   [SOLVED] bfa_custom_query Pagination (http://forum.bytesforall.com/showthread.php?t=23070)

CrouchingBruin Feb 18, 2015 09:19 AM

[SOLVED] bfa_custom_query Pagination
 
The function bfa_custom_query was added to the theme in version 1.2.2. As the name suggests, the function allows you to create your own custom queries. For example, if you want an index/blog page that displayed the posts from four different categories, it is now easy to do. I've discovered a problem, however, with the way the function handles pagination.

For custom queries which return a number of posts that is larger than what has been set for the page size, the pagination control displays the correct number of tabs. For example, if the query returns 25 posts, then three tabs are displayed: 1, 2 & 3. The first two pages should display 10 posts each and the last page should display five posts. However, clicking on any of the pagination tabs displays the posts from the first page and not the posts for the corresponding page. The URL is correct for the page (e.g., /page/2/) but the page displays the posts from the first page and not the posts for the page being viewed.

The cause of the problem is described in the Wordpress codex for query_posts:
Quote:

Pagination won't work correctly, unless you set the 'paged' query var appropriately: adding the paged parameter
If you follow the link to the codex page for adding the paged parameter to a query, it describes how to call the get_query_var to retrieve the correct page number:
Quote:

If query_posts or WP_Query is altering the main loop and the "paged" parameter is not set you'll need to add it with get_query_var(). This is so WordPress knows exactly what page it's on.
Since I can't call get_query_var from the virtual templates, I fixed the problem by making the following change to the bfa_custom_query function in the /includes/template_tags.php file:
Code:

function bfa_custom_query( $bfa_custom_query = '') {
        wp_reset_query();
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        query_posts( $bfa_custom_query . '&paged=' . $paged);

}

Pagination now works correctly.

juggledad Feb 18, 2015 10:24 AM

Thank you for the find and the fix, I'll pass it along.


All times are GMT -6. The time now is 01:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.