这是我的代码,但它无法工作。
global $post;
echo get_the_title( wp_get_post_parent_id( $post->post->ID ) );
但是这并没有起作用。 提前谢谢你。
这是我的代码,但它无法工作。
global $post;
echo get_the_title( wp_get_post_parent_id( $post->post->ID ) );
对于父页面ID
$post->post_parent;
获取当前页面标题
$post->post_title;
$wp_query->post->post_title;
。 - Ritz Cool对于父页面ID
<?php
echo wp_get_post_parent_id(get_the_ID());
?>
get_the_ID()
函数,因为该函数默认使用 null
值,并检索存储当前文章 ID 的全局文章变量。 - Deelewp.data.select('core/editor').getEditedPostAttribute('parent')
希望对某人有所帮助
<a href="<?= get_permalink($post->post_parent) ?>">
<?= get_the_title($post->post_parent) ?>
</a>
→ <?= the_title() ?>
最新新闻 → 一些新闻标题
function add_script_before_header() {
$current = $post->ID;
$parent = $post->post_parent;
$grandparent_get = get_post($parent);
$grandparent = $grandparent_get->post_parent;
if ($root_parent = get_the_title($grandparent) !== $root_parent = get_the_title($current)) {
echo get_the_title($grandparent);
}
$after = $parent;
if ( is_page_template( 'look.php' ) ) {
echo $after . ' - ';
}
}