我正在构建一个Word Press主题,我正在创建一个简短的代码添加到页面中,这些代码会将所有子页面拉到父页面上,但它会拉动网站中的所有页面
如何缩小范围以显示父级的子页面
这是我的函数文件中的最新内容
function my_function() {
$args = array(
'post_type' => 'page',
'post_status' => 'publish',
'parent' => 0,
'hierarchical' => 20,
'child_of' => $post->ID
);
$children = get_pages($args);
$result = "<div class='row'>";
foreach ( $children as $child )
{
$child_id = $child->ID;
$url = get_permalink( $child_id );
$thumb = get_the_post_thumbnail($child_id, array(240, 240));
$title= $child->post_title;
$link = "<a href='$url'>$thumb<div class='product-title'>$title</div></a>";
$result .= "<div class='col-md-3 product-item'>$link</div>";
}
$result .= "</div>";
return $result;
}
add_shortcode('show_child_pages', 'my_function');