一个小脚本把wordpress的博客文章搞砸了


a little script messes up wordpress blog posts

我使用这个脚本来显示最近的帖子:

<ul>
<?php query_posts('showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<li><?php the_content_limit(250); ?></li>
<?php endwhile;?>
</ul>

我把这个放在了header.php中。它完成了任务,但所有其他帖子和页面都会被搞砸。当我尝试加载任何普通页面(page.php)时,我只能从两篇博客文章和类似问题中获得内容。这不是_content_limit的问题。我也试过摘录——也是一样。

有什么想法可以避免这个问题,但最近仍有帖子?

通常不将query_posts放在标头中。在新查询使用此<?php wp_reset_query(); ?> 之前,请尝试创建一个新文件以包含在其中