检查页面是父页面还是子页面? [英] Check if a page is a parent or if it's a child page?
本文介绍了检查页面是父页面还是子页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以检查页面是父页面还是子页面?
Is it possible to check if a page is a parent or if it's a child page?
我的页面设置如下:
-- 父
----子页面1
----子页面2
等
如果它是父页面,我想显示某个菜单,如果它在子页面上,我想显示不同的菜单.
I want to show a certain menu if it's a parent page and a different menu if it's on the child page.
我知道我可以执行以下操作,但我想让它更动态一些,而不包含特定的页面 ID.
I know I can do something like below but I want to make it a bit more dynamic without including specific page ID's.
<?php
if ($post->post_parent == '100') { // if current page is child of page with page ID 100
// show image X
}
?>
推荐答案
您可以测试帖子是否是这样的子页面:
*(来自http://codex.wordpress.org/Conditional_Tags)*
You can test if the post is a subpage like this:
*(from http://codex.wordpress.org/Conditional_Tags)*
<?php
global $post; // if outside the loop
if ( is_page() && $post->post_parent ) {
// This is a subpage
} else {
// This is not a subpage
}
?>
这篇关于检查页面是父页面还是子页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文