已使用互联网的代码示例制作简码以返回特定页面。然而,短代码似乎不是呈现,而是显示短代码文本。该功能已在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');
错误?输出? $内容是在哪里引用的? – 2013-04-08 11:01:28
短代码的引用就像是在一个帖子里面[insert_page page =“154”] – 2013-04-08 11:03:30
请把你如何在帖子中调用短代码。另外,从你的链接,你使用'do_shortcode'方法来测试它吗? – Jon 2013-04-08 11:03:45