如果您想实现相同的目标(请参阅此处),但这次是标题,
你可以这样做:
<?php
if ($post->post_parent!=0) {
// for child pages
$permatitle = get_post_meta(end( get_ancestors( get_the_ID(), 'page' )), '_base_page_subtitle', true);
} elseif($post->ID==0||count(get_pages('child_of='.$post->ID))==0) {
//for HP or pages with no child
$permatitle = get_post_meta(get_option( 'page_on_front' ), '_base_page_subtitle', true);
} else {
// for top level pages/parents
$permatitle = get_post_meta($post->ID, '_base_page_subtitle', true);
}
或者更好的是,将两者结合起来:
<?php
if ($post->post_parent!=0) {
// Handling of Child Pages
$permalink = get_permalink( end( get_ancestors( get_the_ID(), 'page' )));
$permatitle = get_post_meta(end( get_ancestors( get_the_ID(), 'page' )), '_base_page_subtitle', true);
} elseif($post->ID==0||count(get_pages('child_of='.$post->ID))==0) {
// Homepage or Pages with no Parent
$permatitle = get_post_meta(get_option( 'page_on_front' ), '_base_page_subtitle', true);
$permalink = home_url();
} else {
// Handling of Top Level/Parent Pages
$permatitle = get_post_meta($post->ID, '_base_page_subtitle', true);
$permalink = get_permalink( end( get_ancestors( get_the_ID(), 'page' )));
}
那么你可以在之后执行此操作:
<a href="<?php echo $permalink; ?>" title="<?php echo $permatitle; ?>">