php - 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 的页面。我该如何实现呢?
解决方案
不能只在后端创建一个页面并使用“设置>阅读>首页显示”将其设置为静态首页?
如果您希望页面包含在您的主题中,您可以创建一个页面模板,然后在后端创建一个页面并在那里使用该模板。
https://developer.wordpress.org/themes/template-files-section/page-template-files/
但如果你刚开始学习 php,我不建议你直接进入 WordPress 开发。我会先学习php。否则你很容易感到困惑,在某些时候你将无法区分 php 和 WordPress 的特定函数、变量、约定……。
推荐阅读
- python - 任意选择使用带有即时客户端的 cx_Oracle 失败
- javascript - 在 Adobe Pro 中使用 javascript 重命名文件
- sql - SQL server 2000 内部错误 8624 在相同代码中运行了 10 年
- html - 父 div 是 flex,子 div 是具有 flex:1 的列。如何将右侧栏的内容推送到栏的右侧?
- powershell - 如何在 Powershell Invoke-Command 中使用 appcmd 添加虚拟目录?
- r - 使用`:=`时,R data.table lapply不会汇总到组级别
- powershell - 读取文件元数据时出现日期时间错误
- sparklyr - 如何在本地模式下使用 spark_read_jdbc
- javascript - Vue模型:绑定嵌套数据
- php - 如何使用 ajax 加载带有 PHP 变量的 PHP 文件