WordPress function: has_parentpage()

by Rainer Bendig on March 16, 2009

I just created a conditional function for WordPress to check, if the current page has a parent page (or if the page is a sub page). It works outside the main loop, and also inside. To use this function, you need WordPress 2.5 or higher.


Download function


Example usage

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

<?php if ( has_parentpage() ): ?>
<p> This page has a parent page. </p>
<?php endif ?>

<?php endwhile; ?>

Leave your comment

Required.

Required. Not published.

If you have one.