【发布时间】:2016-06-09 09:23:33
【问题描述】:
我有自定义代码,可在我网站的标题菜单中显示最新的 2 篇博文。
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=2');
while ($recentPosts->have_posts()) :
$recentPosts->the_post();
?>
<?php the_permalink(); ?>
<?php the_post_thumbnail_url('thumbnail'); ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile; ?>
它运行良好,除了当我在 Wordpress 中查看实际博客文章时。例如,当查看标题应该显示the_title();...而不是显示实际帖子的标题时,它会显示标题菜单中最后一个“最近的帖子”的标题。
因此,不知何故,我需要使标头中的此最近帖子代码对其自身唯一,以使其不会影响实际博客帖子页面上的数据。有什么想法吗?
【问题讨论】:
标签: php wordpress wordpress-theming