在我的主循环中,我需要将适当的html标记合并到一个条件中,以测试父页面的标题是否匹配子页面的标题,以及是否显示(或不显示)某些内容。默认值可能是保留h1标记,否则不显示。
<!-- 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)我想在这里显示h1。。。
http://howlingwolfmedia.com/site3/my-club/facilities/但不是在这里: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; ?>
SO网友:lberelson
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; ?>