首页 > 解决方案 > WordPress 循环 - 显示特定页面

问题描述

我正在尝试使用 WordPress 构建一个单页主题。我当前的循环如下所示:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<h2>
  <?php the_title(); ?>
  </a>
</h2>
<div class="entry">
  <?php the_content(); ?>
</div>

<?php endwhile; endif; ?>

我只想显示一个特定的页面,例如 id 为 5 的页面。我该如何实现呢?

标签: phpwordpressloops

解决方案


不能只在后端创建一个页面并使用“设置>阅读>首页显示”将其设置为静态首页?

如果您希望页面包含在您的主题中,您可以创建一个页面模板,然后在后端创建一个页面并在那里使用该模板。

https://developer.wordpress.org/themes/template-files-section/page-template-files/

但如果你刚开始学习 php,我不建议你直接进入 WordPress 开发。我会先学习php。否则你很容易感到困惑,在某些时候你将无法区分 php 和 WordPress 的特定函数、变量、约定……。


推荐阅读