我如何对此进行分页?它是wordpress模板中的代码,我用它来获取第一个字母的帖子。我只想要10页。
$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 of 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().
}
?>
我知道我们可以控制不。 posts.But如何分页? 通常在wordpress模板中的普通循环中,它的工作原理如下
<?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; ?>
但在这种情况下它确实起作用。
答案 0 :(得分:1)
这是一个应该有帮助的例子:
<?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);
?>