WordPress.org

Ready to get started?Download WordPress

Forums

Query posts and pagination problem (1 post)

  1. chavo
    Member
    Posted 3 years ago #

    Sin WordPress 3.X I can't figure out how to get pagination working with query_posts. With older versions I usually used querys_posts and everything works fine. But now, my code doesn't works. I read a lot of possible solutions but no one works for me.

    I place my code in archive.php and looks like this:

    <?php
    $cat = get_query_var('cat');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $sticky=get_option('sticky_posts');
    $args=array(
    'category__in'=> array($cat),
    'post__not_in' => $sticky,
    'paged'=>$paged,
    'posts_per_page' => 4
    );
    query_posts($args); ?>
    <?php // The Loop ?>
    <?php if (have_posts()) : ?>
    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    <?php while (have_posts()) : the_post(); ?>
    // my stuff
    <?php endwhile; endif; ?>

    According to WordPress 3.0.2 note
    Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since WordPress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the same. .
    So, I replace this:
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    for this:
    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    I also tried with this:
    $paged = (get_query_var('paged'));
    Nothing works (it doesn't show pagination links in fact).

    I tried using a new WP_Query like this:

    <?php
    	$query = new WP_Query('category__in='.get_query_var('cat').'&posts_per_page=1&paged=' . get_query_var('page') );
    	 ?>

    Not working.

    The only way to get pagination working is setting amount of posts to show from admin panel. But that's not what I want because I need to specify different amount of posts based on categories.

    Anyone can help me?

    Thanks in advance.

    ps: sorry for my bad english

Topic Closed

This topic has been closed to new replies.

About this Topic