Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi I have page displaying 20 featured images and info of a specific category, I wish to able to have pagination so I can have multiple pages for the category.

How do I do this? I cant seem to get it work.

Any help would be appreciated

Thanks

<?php get_header(); ?>
<div class="modus-grid">
     <?php query_posts(array('category__in' => array(5), 'posts_per_page' => 20)); ?>
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                    <?php $currentid = get_the_id(); ?>

                    <div class="grid-box grid-block mod-box width33">

                        <div class="view view-first">                                
                                <?php if (get_the_post_thumbnail($currentid, array(167, 167)) != "") { ?>

                                   <a href="<?php the_permalink(); ?>" /><?php echo get_the_post_thumbnail($currentid, array(300,600)); ?></a>
                                <?php } else { ?> 
                                    <a href="<?php the_permalink(); ?>" /><img src='<?php bloginfo('template_url') ?>/images/default.png' alt='Default'/></a>
                                <?php } ?>

                            <div class="mask">  
                                <h2><a href="<?php the_permalink(); ?>"><?php echo get_the_title($currentid); ?></a></h2>
                                <p><?php echo get_the_excerpt( $post->parent ); ?></p>
                                <a href="<?php the_permalink(); ?>" class="info">Read More...</a>
                            </div>
                        </div> 
                    </div> 

                    <?php
                endwhile;
            endif;

            wp_reset_query();
            ?> 
            <div class="clearfix">
</div>
<?php get_footer(); ?>
share|improve this question
What template file is this, and why are you using query_posts()? – Chip Bennett Nov 29 '12 at 13:40
possible duplicate of Pagination not working with custom loop – Chip Bennett Nov 29 '12 at 13:44
I created a custom page template for the yootheme master theme. I used query_posts because that's the only way I know how to do it. My php is not very good. – rt840 Nov 29 '12 at 13:49

1 Answer

You are not passing any pagination parameters. Like this, from the Codex...

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query( 'paged=' . $paged );

Notice that code uses WP_Query not query_posts. Don't use query_posts. It is pretty much never the best choice for creating a loop.

The top of your Loop should look like...

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$my_query = new WP_Query(array('category__in' => array(5), 'posts_per_page' => 20,'paged'=>$paged)); ?>
    <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) :
         the_post(); ?>

And then the rest of your loop.

You probably also want next_posts_link and previous_posts_link.

share|improve this answer
Hi, thanks a lot for help, when I tried the code it created a never ending page I obviously did it wrong. – rt840 Nov 29 '12 at 19:12
Here is the code < i160.photobucket.com/albums/t195/rt840/tedwdws.jpg > – rt840 Nov 29 '12 at 19:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.