반응형
워드프레스에서 부모 페이지 ID와 현재 페이지의 제목을 얻는 방법은?
여기 내 코드가 작동하지 않는 것이 있습니다.
global $post;
echo get_the_title( wp_get_post_parent_id( $post->post->ID ) );
하지만 이건 안 돼요
미리 감사드립니다.
상위 페이지 ID의 경우
$post->post_parent;
현재 페이지 제목의 경우
$post->post_title;
상위 페이지 ID의 경우
<?php
echo wp_get_post_parent_id(get_the_ID());
?>
구텐베르크에서:
wp.data.select('core/editor').getEditedPostAttribute('parent')
희망은 누군가에게 도움이 될 것입니다.
원하는 경우: 포스트 부모에 대한 링크를 만듭니다.
<a href="<?= get_permalink($post->post_parent) ?>">
<?= get_the_title($post->post_parent) ?>
</a>
→ <?= the_title() ?>
결과는 다음과 같습니다.
최신 뉴스 → 일부 뉴스 제목
Astra 테마 및 페이지 템플릿 보기.php 나는 이것을 했습니다: $post->post_parent; 내 기능이 루프를 벗어나면 nbot이 작동하지 않을 것입니다.functions.php로 실행합니다.$post->post_parent는 페이지 템플릿에 삽입할 때는 완벽하게 작동하지만 테마 기능을 편집할 때는 작동하지 않습니다 ;)
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 . ' - ';
}
}
언급URL : https://stackoverflow.com/questions/43249168/how-to-get-parent-page-id-and-title-of-current-page-in-wordpress
반응형
'itsource' 카테고리의 다른 글
MySQL에서 병합 문을 사용할 수 있는지 여부 (0) | 2023.09.19 |
---|---|
인터넷 익스플로러 8의 jQuery 문제 (0) | 2023.09.19 |
커밋과 선택 사이의 Oracle 시차 (0) | 2023.09.19 |
에서 출력의 공백 xmlns 특성을 방지하는 방법.NET의 Xml 문서? (0) | 2023.09.19 |
날짜 열을 내림차순으로 색인하는 것이 좋습니까? (0) | 2023.09.19 |