Paginating wordpress custom queries
How do i paginate this? It's a code in wordpress template I'm using to get posts by their first letter. I only want 10 in a page.
$postids=$wpdb->get_col($wpdb->prepare("
SELECT ID
FROM $wpdb->posts
WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
ORDER BY $wpdb->posts.post_title",$first_char));
if ($postids) {
$args=array(
'post__in' => $postids,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List o开发者_高级运维f Posts Titles beginning with the letter '. $first_char;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
}
?>
I know that we can control the no. of posts.But how to paginate? Usually in ordinary loops within wordpress template it works like this
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav"><<</span> Show More', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Show Previous <span class="meta-nav">>></span>', 'twentyten' ) ); ?></div>
</div><!-- #nav-above -->
<?php endif; ?>
But it doest work in this case.
here's an example that should help:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky=get_option('sticky_posts');
$args=array(
'cat'=>3,
'caller_get_posts'=>1,
'post__not_in' => $sticky,
'paged'=>$paged,
);
query_posts($args);
?>
query_posts
精彩评论