$20
pagination with custom query with permalinks in functions.php
I've spent all day trying to figure this out, I've done all the tutorials that I could find on the web, but I still can't get the pagination to work properly.
WP-PageNavi shows 3 pages (there are 19 posts total) and the limit per page is 7, but when clicking on the nav buttons just reloads the same posts.
this is an example of the problem:
http://www.dekritischebelegger.nl/archives
/category/Aandelen/2010/05/page/3/
I have used this code to get archives by category
http://www.jayminkapish.com/2009/06/16/date-archive-for-a-category/
but I modified it to suit my needs. Anyway, it doesn't say anything about pagination
function my_date_archive_for_category() {
...
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'cat' => $category_array["term_id"],
'year'=> $request_parts["4"],
'monthnum'=>$request_parts["5"],
'paged' => $paged
));
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?>>
<?php global $post; ?>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
<?php
else:
$is404 = true;
endif;
}
else {
$is404 = true;
}
}
else {
$is404 = true;
}
if($is404) {
include(TEMPLATEPATH . '/404.php');
} ?>
</div><!--end for left-r-->
</div>
<div id="right">
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer();
exit;
}
}
add_action('init','my_date_archive_for_category');
I haven't posted all the code, but I attached the functions.php file
paul de wouters | 06/01/10 at 6:22pm
| Edit
(2) Possible Answers Submitted...
-

Last edited:
06/01/10
7:04pmBill Hunt says:Looks like a simple typo maybe?
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'cat' => $category_array["term_id"],
'year'=> $request_parts["4"],
'monthnum'=>$request_parts["5"],
'paged' => $paged
));
Give that a shot, maybe?- 06/01/10 7:04pm
Bill Hunt says:Looks like a simple typo maybe?
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'cat' => $category_array["term_id"],
'year'=> $request_parts["4"],
'monthnum'=>$request_parts["5"],
'paged' => $paged
));
Give that a shot, maybe? - 06/01/10 7:05pm
Bill Hunt says:Sorry, changed $page to $paged in that first bit.
- 06/01/10 7:55pm
paul de wouters says:Hi Bill,
thanks for the typo, but that didn't fix it.
the URL was not displayed, so here it is again
http://www.dekritischebelegger.nl/archives/category/Aandelen/2010/05/page/3/ - 06/01/10 8:13pm
Bill Hunt says:Everything else in that block is correct; I assume that it's not getting all of the necessary arguments from before? Can you post the full source from above that part, and var_dump($category_array, $request_parts) and post the result?
- 06/01/10 8:30pm
paul de wouters says:I added
var_dump($category_array, $request_parts);
var_dump($GLOBALS['wp_query']);
is that correct?
- 06/01/10 8:31pm
paul de wouters says:also the whole functions.php is attached
- 06/01/10 7:04pm
-
Last edited:
06/01/10
9:03pmOleg Butuzov says:after the function query_posts run please make
to debug variables that passed to the query_postsvar_dump($GLOBALS['wp_query'])- 06/01/10 8:27pm
paul de wouters says:done
- 06/01/10 8:30pm
Oleg Butuzov says:you can remove var_dump. $paged isn't there =)
wait a minute.... - 06/01/10 8:36pm
Oleg Butuzov says:function get_page_variable(){
$url = $_SERVER['REQUEST_URI'];
@list(,$page) = @explode('page/', $url);
$page = rtrim($page, '/');
return intval($page) == 0 ? 1 : intval($page);
}
$paged = get_page_variable();
insted
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; - 06/01/10 8:47pm
paul de wouters says:Oleg
that functions seems to have done the trick.
how does it work?
- 06/01/10 8:51pm
Oleg Butuzov says:well. my last expirience with category/date/date wasn't susseful. even if i had rewrites rules all gose to canonical rewrites ... i have fix all this stuff in a way you show to people right now.
i have get a problem with paging =) but i have solve it in a bit different way - i am adding rewrite rules to match the url pattern. its complicated way for a non proffesional. so in your way a batter was just to parse a url for a page variable =)
cheers! - 06/01/10 9:05pm
paul de wouters says:thanks for the explanation.
so you are using the .htaccess rules to do the same?
if you want you can also post that solution, just out of curiosity
- 06/01/10 8:27pm
This question has expired.
Current status of this question: Completed





