在WordPress开发过程中,经常需要在不同位置调用特定单页的内容。本文将详细介绍几种实用的调用方法。
通过页面ID是最直接的调用方式:
post_content); ?>
如果不知道页面ID,可以使用页面别名:
post_content); ?>
创建自定义短代码实现灵活调用:
function display_page_content($atts) {
$atts = shortcode_atts(array(
'id' => ''
), $atts);
$page = get_post($atts【'id'】);
return apply_filters('the_content', $page->post_content);
}
add_shortcode('display_page', 'display_page_content');
使用时只需在编辑器中输入:【display_page id="42"】
如果只需要调用页面的特定信息:
掌握这些方法后,你就可以灵活地在主题的任何位置调用单页内容,大大提升开发效率。