In my main loop, I need to incorporate proper html markup into a conditional to test if title of parent page matches title of child page and do (or do not) display certain content. Default might be to keep h1 tag , otherwise do not display.
<!-- 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>
<?php
$children = get_pages('child_of='.$post->ID);
if( count( $children ) != 0 ) {
echo 'NO children';
}
else { echo 'has children';}
?>
<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/
solution here as function:
function testchildren () {
global $post;
$childtest = get_pages('child_of='.$post->ID);
if( count( $childtest ) != 0 ) {
return false;
} else {
return true;
}
}
and implementation as markup:
<?php if (have_posts()) : while (have_posts()) : the_post() ; ?>
<h2><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?> </h2>
<?php if ( testchildren() ) : ?>
<h1 style="margin-top:6px; margin-bottom:12px;"><?php the_title(); ?></h1>
<?php endif; ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php if (have_posts()) : while (have_posts()) : the_post() ; ?> <h2><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?> </h2> <?php if ( testchildren() ) : ?> <h1 style="margin-top:6px; margin-bottom:12px;"><?php the_title(); ?></h1> <?php endif; ?> <?php the_content(); ?> <?php endwhile; endif; ?>