I have a custom template listing only posts of one category (category-XX.php)
Here I am listing only events, future events and passed events. Using the plugin 'MR Event' I get the date of all events easily into a custom field.
This list got quite long now and I was looking for a code to paginate the custom loop. Paging in a $pageposts = $wpdb->get_results($wp_query->request, OBJECT); loop is not so easy, but I found a solution here: wordpress.org/support/topic/232627
As this stuff is for advanced users only, I will give you the complete content of my category-XXX.php here.
To be seen here: http://www.linedancestompers.de/category/events/
<?php get_header(); ?>
<!-- cat 'your cat ID' template name category-ID.php -->
<div id="content">
<?php if(!is_paged()) { ?>
<?php if ( function_exists('mr_event_list_qf') ) { ?>
<h2>Kommende Termine:</h2>
<?php mr_event_list_qf('date_format=d.m.Y','%DATE%: <a href="%URL%" title="%TITLE%" >%TITLE%</a>') ?>
<?php } ?>
<?php } ?>
<h2>Alle Termine<?php if ($paged != 1 && $paged) { echo(" Seite $paged" ); } ?>:</h2>
<?php
$total = "
SELECT $wpdb->posts.*
FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
WHERE $wpdb->postmeta.meta_key = 'mr_event'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
ORDER BY $wpdb->postmeta.meta_value DESC
";
$totalposts = $wpdb->get_results($total, OBJECT); //see wordpress.org/support/topic/232627
$ppp = intval('12'); //12 posts per page you might use $ppp = intval(get_query_var('posts_per_page'));
$wp_query->found_posts = count($totalposts);
$wp_query->max_num_pages = ceil($wp_query->found_posts / $ppp);
$on_page = intval(get_query_var('paged'));
if($on_page == 0){ $on_page = 1; }
$offset = ($on_page-1) * $ppp;
$wp_query->request = "
SELECT $wpdb->posts.*
FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
WHERE $wpdb->postmeta.meta_key = 'mr_event'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
ORDER BY $wpdb->postmeta.meta_value DESC
LIMIT $ppp OFFSET $offset";
$pageposts = $wpdb->get_results($wp_query->request, OBJECT);
?>
<?php if ($pageposts): ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="event">
<ul><li><?php if($mr_event_meta = get_post_meta($post->ID, 'mr_event', true)) { echo date('j.m.Y', $mr_event_meta);echo ' ';echo date('G:i', $mr_event_meta);echo ' Uhr<br />'; } ?></li></ul>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<div class="contenttext">
<?php the_content() ?>
</div>
</div>
<?php endforeach; ?>
<?php else : ?>
<p>No matching entries found.</p>
<?php endif; ?>
<div class="navigation">
<p><span class="navleft"><?php previous_posts_link('« Vorherige Seite') ?></span>
<span class="navright"><?php next_posts_link('Nächste Seite »') ?></span></p>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
having questions? Join us and ask!