Status
Not open for further replies.

rahul23

Active Member
144
2011
37
0
Hello, i want to paginate my wordpress query. the code is

<?php $recent = new WP_Query("cat=1&showposts=20"); while($recent->have_posts()) : $recent->the_post();?>
<?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" width="90" height="90" alt="<?php the_title(); ?>" /></a>
<?php else: ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php bloginfo('template_url'); ?>/images/thumbnail.png" width="90" height="90" alt="<?php the_title(); ?>" /></a>
<?php endif; ?>
<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php endwhile; ?>
This query returns 20 results, but i want to paginate it and show 5 results in each page.

WP experts, help me
 
Last edited:
4 comments
Try this:

Code:
<?php $recent = new WP_Query("cat=1&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
                <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
                    <a href="<?php the_permalink() ?>"  rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;"  src="<?php echo get_post_meta($post->ID, "thumbnail", true);  ?>" width="90" height="90" alt="<?php the_title(); ?>"  /></a>
                <?php else: ?>
                       <a href="<?php the_permalink() ?>"  rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;"   src="<?php bloginfo('template_url'); ?>/images/thumbnail.png"  width="90" height="90" alt="<?php the_title(); ?>" /></a>
                <?php endif; ?>                
                <h1><a href="<?php the_permalink() ?>"  rel="bookmark"><?php the_title(); ?></a></h1>
 
Thanks for reply.

But i don't just want to display just 5 results. After that i want to get page navigation at the end like Pages 1,2,3,4.

simply adding <?php if (function_exists('wp_pagenavi')) { ?><?php wp_pagenavi(); ?><?php } ?> is not resulting navigation.
 
are you using this plugin?
Code:
 http://wordpress.org/extend/plugins/wp-pagenavi/
If yes, did you follow the instructions?
Code:
 http://wordpress.org/extend/plugins/wp-pagenavi/installation/
 
Yes i am using wp-pagenavi plugin and installed and its working fine.

Now i want to create a custom query(like search results from a single category) and want to make wp-pagenavi work on it.

Pagenavi is not working with my query. May be i need to edit my query and insert it inside a search results loop.

---------- Post added at 02:08 PM ---------- Previous post was at 01:56 PM ----------

I make my requirement more clear. If a user searches for the word "wordpress", it has to search only in one category, which can be done by using my code.

Now if the search gives 20 results, i want to post 5 by 5 using pagenavi plugin which i couldn't figure it out yet.

---------- Post added at 05:24 PM ---------- Previous post was at 02:08 PM ----------

Ok, i got it done by passing the new query to pagenavi.

Thanks for all replies :).
 
Status
Not open for further replies.
Back
Top