php 如果页面父级等于 ID(编号)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14335648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:05:20 来源:igfitidea点击:
If page parent equals ID (number)?
提问by Rob
I have an if statement that is checking the ID of the page, using the following:
我有一个 if 语句正在检查页面的 ID,使用以下内容:
<?php if ( is_page(10) ) { ?>
How can I do something like if page parent is 10?
如果页面父级为 10,我该怎么做?
回答by Reigel
try something like this
尝试这样的事情
global $post;
if ($post->post_parent == 10) {
echo "parent's id is 10";
}
回答by suraj singh
$id = wp_get_post_parent_id( get_the_id() );
Now $idhas parent page id
现在$id有父页面 id
回答by laurent
Get the current page object, then get its parent ID:
获取当前页面对象,然后获取其父ID:
global $wp_query;
$currentPage = get_page($wp_query->get_queried_object_id());
if (is_page($currentPage['post_parent'])) {
}

