WordPress.org

Ready to get started?Download WordPress

Forums

Need a conditional to test if title of parent page matches title of child page (2 posts)

  1. berelson@hotmail.com
    Member
    Posted 2 months ago #

    In my main loop, I need a conditional to test if title of parent page matches title of child page. Default might be to keep h1 tag , otherwise do not display.

    Here's the code without conditional. :

    <!-- basic loop -->
    <?php if (have_posts()) : while (have_posts()) : the_post() ; ?>
    <h2>
        <?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?>
    </h2>
    
    <h1 style="margin-bottom:12px"><?php the_title(); ?></h1> 
    
    <?php the_content(); ?>
    <?php endwhile; endif; ?>

    ex) I want h1 to show here... http://howlingwolfmedia.com/site3/my-club/facilities/

    but not here: http://howlingwolfmedia.com/site3/my-club/

  2. berelson@hotmail.com
    Member
    Posted 2 months ago #

    found this post: http://wordpress.org/support/topic/if-children-parent-title-if-not-no-title-1?replies=13 and added echo which works. Now need to fix syntax to account for desired html markup.

    ?php
    $children = get_pages('child_of='.$post->ID);
    if( count( $children ) != 0 ) { 
    
    echo 'does NOT have children';
    
    }
    else { echo 'has children';}
    ?>

Reply

You must log in to post.

About this Topic