有人能帮我修改代码以消除我的问题吗?我在循环之前使用这一行:
<?php query_posts(\'cat=3&showposts=\'.get_option(\'posts_per_page\')); ?>
对于上下文:
<?php get_header(); ?>
<div id="page-wrap">
<div id="content">
<div class="post-wrap">
<?php query_posts(\'cat=9&showposts=\'.get_option(\'posts_per_page\')); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class(\'post\') ?> id="post-<?php the_ID(); ?>">
<h2 class="blog-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small></small>
<div class="entry">
<?php the_content(\'Read the rest of this entry »\'); ?>
</div>
<p class="postmetadata">Posted <?php the_time(\'M j Y\') ?></p>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(\'« Older Entries\') ?></div>
<div class="alignright"><?php previous_posts_link(\'Newer Entries »\') ?></div>
</div>
<div class="clear"></div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn\'t here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
</div><!-- .post-wrap -->
</div><!-- #content -->
我相信这就是导致我的最新帖子出现两次的原因。这条线应该还有其他东西吗??
最合适的回答,由SO网友:fxfuture 整理而成
尝试用以下代码替换您的代码:
$wp_query = new WP_Query();
$wp_query->query( array( \'cat\' => \'9\', \'posts_per_page\' => get_option( \'posts_per_page\' )));
SO网友:booota
代替
<?php query_posts(\'cat=9&showposts=\'.get_option(\'posts_per_page\')); ?>
使用
<?php query_posts(\'cat=9&posts_per_page=\'.get_option(\'posts_per_page\')); ?>
在while循环之后(就在endwhile之后)插入
wp_reset_query();
如果无法解决问题,请尝试获取get\\u选项的值(“每页posts\\u”),以查看它是否是罪魁祸首。
如果没有任何解决方法,请尝试@fxfutures-answer。