如何在wordpress自定义主题中显示页面内容?
How to display page content in custom theme in wordpress?
我已经搜索了几个小时了,我可能会忽略它或者在 google 中提出错误的问题,但我真的很想知道如何获取我输入的内容,例如WordPress 仪表板中的“关于”页面,显示在我的 page.php
.
上
如果您需要通过 id 显示特定的 post/page,Wordpress 具有该功能
<?php get_post( $id, $output, $filter ); ?>
文档在这里:https://codex.wordpress.org/Function_Reference/get_post
你可以像这样获取任意页面的内容:
$page = get_page_by_title('About');
我是按标题抓页,你也可以拿by ID or URL path
然后你可以通过输出post object的post_content
属性来显示它。请注意,如果您需要对其进行格式化,则需要应用 the_content
过滤器:
echo apply_filters('the_content', $page->post_content);
我已经搜索了几个小时了,我可能会忽略它或者在 google 中提出错误的问题,但我真的很想知道如何获取我输入的内容,例如WordPress 仪表板中的“关于”页面,显示在我的 page.php
.
如果您需要通过 id 显示特定的 post/page,Wordpress 具有该功能
<?php get_post( $id, $output, $filter ); ?>
文档在这里:https://codex.wordpress.org/Function_Reference/get_post
你可以像这样获取任意页面的内容:
$page = get_page_by_title('About');
我是按标题抓页,你也可以拿by ID or URL path
然后你可以通过输出post object的post_content
属性来显示它。请注意,如果您需要对其进行格式化,则需要应用 the_content
过滤器:
echo apply_filters('the_content', $page->post_content);