• Resolved md84

    (@md84)


    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>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter md84

    (@md84)

    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>
    Thread Starter md84

    (@md84)

    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 'https://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>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pagination question’ is closed to new replies.