使用来自互联网的代码示例制作短代码以返回特定页面。但是,短代码似乎没有呈现,而是显示了短代码文本。该函数已在内部定义functions.php
。
代码如下:
/* Code taken from:
* http://alex.leonard.ie/2010/09/09/wordpress-shortcode-to-insert-content-of-another-page/
*/
function pa_insertPage($atts, $content = null) {
// Default output if no pageid given
$output = NULL;
// extract atts and assign to array
extract(shortcode_atts(array(
"page" => '' // default value could be placed here
), $atts));
// if a page id is specified, then run query
if (!empty($page)) {
$pageContent = new WP_query();
$pageContent->query(array('page_id' => $page));
while ($pageContent->have_posts()) : $pageContent->the_post();
// assign the content to $output
$output = get_the_content();
endwhile;
}
return $output;
}
add_shortcode('insert_page', 'pa_insertPage');