使用頁(yè)面別名調(diào)用 如果不知道頁(yè)面ID,可以使用頁(yè)面別名: post_content);?> 使用短代" />
當(dāng)前位置 主頁(yè) > 技術(shù)大全 >
在WordPress開(kāi)發(fā)過(guò)程中,經(jīng)常需要在不同位置調(diào)用特定單頁(yè)的內(nèi)容。本文將詳細(xì)介紹幾種實(shí)用的調(diào)用方法。
通過(guò)頁(yè)面ID是最直接的調(diào)用方式:
post_content); ?>
如果不知道頁(yè)面ID,可以使用頁(yè)面別名:
post_content); ?>
創(chuàng)建自定義短代碼實(shí)現(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');
使用時(shí)只需在編輯器中輸入:【display_page id="42"】
如果只需要調(diào)用頁(yè)面的特定信息:
掌握這些方法后,你就可以靈活地在主題的任何位置調(diào)用單頁(yè)內(nèi)容,大大提升開(kāi)發(fā)效率。