请不要使用query_posts
:) 非常糟糕的做法。所以你希望这个循环得到 3 个帖子......
<!--The-Loop-->
<?php // Loop (Will get every post Except Sticky ones...)
$sticky = get_option( 'sticky_posts' );
/*Let's add pagination to post page and static page*/
/*We need this here to add and maintain Pagination if Template is assigned to Front Page*/
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
$args = array(
/* Add whatever you need here - see http://codex.wordpress.org/Class_Reference/WP_Query */
'paged' => $paged,
'post__not_in' => $sticky,
'ignore_sticky_posts' => 1,
'posts_per_page' => 3
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
if($wp_query->have_posts()):?><?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h3 class="mytitle"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'domain' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<div class="entry">
<?php if ( has_post_thumbnail() ):?>
<div class="featured_img">
<?php
the_post_thumbnail();
echo '<div class="featured_caption">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';
?>
</div><!--/featured_img-->
<?php endif; ?>
<?php // let's enable more link on pages...
global $more;
$more = 0;
?>
<?php the_content(__('Read more','domain')); ?>
<div class="clear"></div>
<div class="custom_fields"><?php the_meta(); ?></div><br/>
<p class="postmetadata">
<?php _e('Filed under:','domain'); ?> <?php the_category(', ') ?> <?php _e('by','domain'); ?> <?php the_author(); ?><br/><?php the_tags(__('Tags:','domain'), ', ', '<br />'); ?>
<?php _e('Posted on: ','domain'); ?><?php the_time(get_option('date_format')); ?><br/>
<?php if ( comments_open() ) {
comments_popup_link(__('No Comments »','domain'), __('1 Comment »','domain'), __('% Comments »','domain'));}
else {
_e('Comments are disabled!','domain');
}
?>
<?php edit_post_link(__(' Edit','domain'), __(' |','domain'), ''); ?>
</p>
</div><!--/entry-->
</div><!--/post_class-->
<?php endwhile; ?>
<div class="clear"></div>
<div class="navigation">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $wp_query->max_num_pages,
'prev_text' => __('Prev','domain'),
'next_text' => __('Next','domain')
) );
?>
</div><!--/Navigation-->
<?php endif; ?><!--END if THE LOOP (3 Posts)-->
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>