从一个页面获取the_content并在另一个页面中显示(Wordpress)
问题描述:
我正在寻找一种方法从我的某个页面获取the_content并将其显示在另一个页面中。最好使用页面块/标题。从一个页面获取the_content并在另一个页面中显示(Wordpress)
我发现了一个代码,似乎工作,但它使用页面ID。有没有办法修改这段代码,以便它使用页slu /标题?
<div>
<?php
$id = 238;
$p = get_page($id);
echo apply_filters('the_content', $p->post_content);
?>
</div>
谢谢。
答
按标题:
<div>
<?php
$page = get_page_by_title('Page Title');
if($page) {
echo apply_filters('the_content', $page->post_content);
}
?>
</div>
通过毛坯:
<div>
<?php
$page = get_page_by_path('page-title');
if($page) {
echo apply_filters('the_content', $page->post_content);
}
?>
</div>
+0
谢谢你的帮助! – chrisbedoya
的名字你的意思是网页块或标题?检查[get_page_by_title](https://codex.wordpress.org/Function_Reference/get_page_by_title)out – d79
它可以是slu or或标题@ d79 – chrisbedoya