在WordPress開發(fā)過程中,經(jīng)常需要在不同位置調(diào)用特定單頁的內(nèi)容。本文將詳細介紹幾種實用的調(diào)用方法。
通過頁面ID是最直接的調(diào)用方式:
post_content); ?>
如果不知道頁面ID,可以使用頁面別名:
post_content); ?>
創(chuàng)建自定義短代碼實現(xiàn)靈活調(diào)用:
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"】
如果只需要調(diào)用頁面的特定信息:
掌握這些方法后,你就可以靈活地在主題的任何位置調(diào)用單頁內(nèi)容,大大提升開發(fā)效率。