WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination question (3 posts)

  1. MD84
    Member
    Posted 4 years ago #

    The code below shows 15 permalinks in a list from category 'film'. Since I have 20 permalinks, 5 will be shown on page 2 (paged=2).

    My problem is: when I use (click/press) a permalink on page 2 the respective post opens, but my permalink-list now shows page 1 instead of page 2.

    I know it have something to do with the default variable '1' in the code below, but how to solve this?

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=film&posts_per_page=15&paged=$paged"); ?>
    <ul style="list-style:none;">
    <?php while(have_posts()) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    <p><?php wp_pagenavi(); ?></p>
    </ul>
  2. MD84
    Member
    Posted 4 years ago #

    I now have this, but it still does not work. The code under else is incorrect. Can somebody help me?

    <?php if(!is_paged($paged)){
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=film&posts_per_page=15&paged=$paged");
    } else {
    query_posts("category_name=film&posts_per_page=15&paged=$paged");
    } ?>
    <ul style="list-style:none;">
    <?php while(have_posts()) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    <p><?php wp_pagenavi(); ?></p>
    </ul>
  3. MD84
    Member
    Posted 4 years ago #

    Solved!

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query = new WP_Query();
    $wp_query -> query('category_name=film&posts_per_page=15&paged=' . $paged);
    ?>
    
    <ul style="list-style:none;">
    <?php while($wp_query -> have_posts()) : $wp_query -> the_post(); ?>
    <li>
    <?php if(is_paged()){ ?>
    <a href="<?php echo 'http://xxx/your_theme_name/?p=' . $post -> ID . '&paged=' . $paged; ?>"><?php the_title(); ?></a>
    <?php } else { ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php }; ?>
    </li>
    <?php endwhile; ?>
    <p><?php posts_nav_link(); ?></p>
    </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic