获取整个页面内容并显示在标题

时间:2017-07-19 08:17:53

标签: php wordpress woocommerce

创建了一个页面并希望显示 header.php 上的所有内容,但它不会显示任何内容。

以下代码:

$page = get_page_by_title( 'TEST' );
$content = apply_filters('the_content', $page->post_content);
echo $content;

还有其他办法吗?

2 个答案:

答案 0 :(得分:1)

尝试执行此操作(只需将123替换为您的网页ID):

$page_object = get_page( 123 );
$my_content=$page_object->post_content;
echo do_shortcode( $my_content );

答案 1 :(得分:1)

使用以下代码获取:

$page = get_page_by_title('TEST', OBJECT, 'page');
echo $page->post_content;

如果页面中添加了短代码并且页面中添加了文本,则使用以下代码假设联系页面:

$page = get_page_by_title('Contact', OBJECT, 'page');
$page->post_content;

// will match square brackets

if (preg_match('^\[(.*?)\]^', $page->post_content))
{
    echo do_shortcode($page->post_content);

}else{

    echo $page->post_content;

}

如果页面替换226中包含文本和短代码,请使用您的页面ID;

$id=226;
$post = get_page($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;

阅读:https://codex.wordpress.org/Function_Reference/get_page_by_title

相关问题