views:

1082

answers:

3

I have a wordpress site, where on the main page I list the content from more categories.

My question is, is there a plugin where I can paginate the results from a category?I mean something like $this->plugin_paginate('category_id'); or smth?

Best Regards,

A: 

If you're using the standard Wordpress loop, even with a query_posts for a category, pagination is automatic with the usual posts_nav_link. Are you trying to paginate for more than one query and more than one category on the same page?

Edit 11/20: I use this in several different places on one page to show the latest post in a category:

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> <?php the_title(); ?></a><?php endwhile; ?>

That link then goes to a category page that paginates for that category: Category Templates « WordPress Codex

I don't know how to paginate different categories on the same page. Must be possible. Maybe ask in the Wordpress forums.

songdogtech
yes more then one query. and more categories :)
Uffo
A: 

This sounds like something that a simple, well-formed query_posts() call can do. I doubt that you'll even need to rely on a plugin. :)

I'm going to assume that you're familiar with the query_posts() function, so let's go ahead and use this example as a base:

// let's get the first 10 posts from category ID 3
query_posts('posts_per_page=10&cat=3');
while(have_posts()):the_post();
    // do Wordpress magic right here
endwhile;

Now, to get the 11th to 20th posts from category 3 (that is, the NEXT 10 posts), we'll want to use the [offset] parameter of query_posts():

// let's get the next 10 posts from category ID 3
query_posts('posts_per_page=10&cat=3&offset=10');
while(have_posts()):the_post();
    // do Wordpress magic right here
endwhile;

For most purposes, that should be sufficient. However, you did mention that you plan on paginating category post lists from the main page alone? I'm assuming that you mean that you have multiple category post lists on your main page, and all these are paginated independently.

With something like that, it looks like you'll have to work a bit with Javascript to do the work for you, along with what I illustrated above.

Richard Neil Ilagan