Php wordpress是否自动理解$post->;身份证还是我需要自己设置
我已经设置了一个快捷码,它会将所有子页面拉到它打开的页面上,但是它会将站点中的所有页面拉到菜单中Php wordpress是否自动理解$post->;身份证还是我需要自己设置,php,wordpress,menu,themes,Php,Wordpress,Menu,Themes,我已经设置了一个快捷码,它会将所有子页面拉到它打开的页面上,但是它会将站点中的所有页面拉到菜单中 function my_function() { $args = array( 'post_type' => 'page', 'posts_per_page' => -1, 'post_parent' => $post->ID, 'order' => 'ASC', 'order
function my_function() {
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$children = get_pages($args);
$result = "<div class='row inner'>";
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');
函数我的函数(){
$args=数组(
“post_type”=>“page”,
“每页帖子数”=>-1,
'post_parent'=>$post->ID,
“订单”=>“ASC”,
'orderby'=>'菜单\u顺序'
);
$children=获取页面($args);
$result=“”;
foreach($childrenas$child)
{
$child_id=$child->id;
$url=get\u permalink($child\u id);
$thumb=get_the_post_缩略图($child_id,array(240240));
$title=$child->post_title;
$link=“”;
$result.=“$link”;
}
$result.=”;
返回$result;
}
添加快捷码(“显示子页面”、“我的函数”);
在post_parent中,我有$post->id,但我不确定是否必须使用我尝试过的get_id函数将其设置为一个变量,它只是把菜单弄得更乱了,我觉得我做错了。
非常感谢您的帮助
这已被标记为重复,但我的问题也没有得到回答
即使在增加了全球$post;在函数的顶部,它仍然会吐出所有菜单项,$post还没有任何值,它位于一个简单的数组($args)中,这只是php,$post在您之前设置它之前不会有任何值
正如您在上面的文档中所看到的,$post ref在wordpress循环中工作您需要在使用它之前设置它:
global$post
@brasofilo-ive现在添加到参数global$post的上方$id=$post->id;但是它仍然会在菜单中显示所有页面$post->ID有效吗?如果你放了一些现有的id怎么办?我在post\u parent中添加了该id仍然没有任何可能是我的参数吗?@brasofilove现在在参数global$post上方添加了该id$id=$post->id;然而,它仍然会吐出菜单中的所有页面