使用这段代码,您可以显示内容,具体取决于它是否为子页面:
<?php
global $post;
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php else : ?>
This is a parent-page.
<?php endif; ?>
但我想再添加一条语句,这样如果父页面有子页面,或者父页面没有子页面,我就可以有不同的内容。下面这样的内容行得通吗?如果是,那么“XXX”是什么?<?php
global $post;
if ( is_page() && $post->post_parent ) : ?>
This is a child-page.
<?php elseif ( is_page() && XXX ) : ?>
This is a parent-page (with one or more children)
<?php else : ?>
This is a parent page without children.
<?php endif; ?>
提前感谢!