【发布时间】:2015-12-16 16:35:18
【问题描述】:
我在我的 wordpress 模板中添加了一个自定义 php 函数,我想在其中回显某个父级下的页面内容:
Departments
-department 1 (get the title and the content clean)
-department 2 (get the title and the content clean)
(...)
到目前为止,我的代码没有按我的意愿工作,标题很好,但我需要过滤内容,所以我只能抓取"<p>" 标记之间的文本。这可能吗?谢谢。
functions.php
function echo_childs_of( $postID ) {
$args = array(
'order' => 'ASC',
'post_parent' => $postID,
'post_status' => null,
'post_type' => 'any'
);
$page_childs = get_children( $args );
if ( $page_childs ) {
foreach ( $page_childs as $child ) {
$title = get_the_title( $child );
$content = get_the_content($child);
$content = strip_shortcodes( $content );
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content);
echo $title;
echo $content;
}
}
}
在我的 php 页面上
echo_childs_of( 7 );
【问题讨论】: