WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditional Statement for Parent Pages Only? (3 posts)

  1. bunnyhello
    Member
    Posted 1 year ago #

    I have a template page I am working on for several different pages, some of which are parent pages, most of which are children and grandchildren.

    The parent pages don't have a title, the children and grandchildren do have the title.

    How would I write a conditional tag that would only call the <h1><?php the_title(); ?></h1> when the page is a child or grandchild?

    Thanks in advance!

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try:

    <?php if( $post->post_parent ) { ?>
    <h1><?php the_title(); ?></h1>
    <?php } ?>
  3. bunnyhello
    Member
    Posted 1 year ago #

    That was perfect! Thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic