Ready to get started?Download WordPress


Pagination not working (2 posts)

  1. victorywp
    Posted 5 years ago #

    <?php query_posts('posts_per_page=20'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( get_post_meta($post->ID, 'image', true) ) { ?>
    "><img alt="<?php the_title_attribute(); ?>" src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&h=105&w=105&zc=0&q=100" />
    <?php } ?>
    <?php endwhile; endif; ?>

    I changed the first line from
    <?php query_posts('showposts=20'); ?>
    <?php query_posts('posts_per_page=20'); ?>

    My problem is that when I click on any number on the pagination, the content doesn't change.
    The url in the browser does change according to the number you clicked, but the actual content doesn't change.

    I have viewed this post
    which is quite similar to my problem but it doesn't apply to me.
    Can anybody help?

  2. stvwlf
    Posted 5 years ago #


    When you use query_posts you have to include the pagination code.

    applying it to your code it becomes

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
          query_posts("posts_per_page=20&amp;paged=$paged"); ?>

    note that the query_posts parameters are in double quotes - that is necessary to translate the PHP variable $paged into its value and not interpret it as a text string of the word $paged.

    (I didn't test this code.)

Topic Closed

This topic has been closed to new replies.

About this Topic