分页在每页上返回相同的帖子

时间:2016-01-18 18:29:05

标签: php

点击"旧帖子"后,每个页面都会返回相同的帖子。这在一次工作正常,但现在不行。以下是我使用的代码:

<?php if ( have_posts() ) : ?>

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' => 6, 'paged' => $paged, 'post_status' => 'publish', 'offset'=> 0, 'category'=> '-1, -9, -16, -17, -119, -318' );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>

<div class="blog-post-wrap">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="post-thumb blog-index">
<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    the_post_thumbnail( 'large' );
} 
?>
</div>

<div class="title-meta-wrap">   

<?php if (strlen($post->post_title) > 75) {
echo substr(the_title($before = '', $after = '', FALSE), 0, 75) . '...'; } else {
the_title();
} ?>
</a>
<p><span class="theauthor"><?php the_date(); ?> <span style="color:#EC7906;"> / </span><?php the_author(); ?> </span></p>

</div>
</div>

<?php endforeach; 
wp_reset_postdata();?>
<?php endif; ?> 
<?php twentyeleven_content_nav( 'nav-below' ); ?> 

我能够将其删除:

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );

就这样:

get_posts( $args );

分页有效,但页面每页只返回一个帖子。有什么想法吗?

0 个答案:

没有答案