現在表示している投稿から post_parent で親ページの ID を取得する
1 2 3 |
<?php $parent_id = $post->post_parent; // 親ページのIDを取得 ?> |
取得したIDから、親ページのスラッグやタイトルを取得して表示する方法
1 2 3 4 5 6 7 8 |
<?php $parent_id = $post->post_parent; // 親ページのIDを取得 $parent_slug = get_post($parent_id)->post_name; // 親ページのスラッグを取得 echo $parent_slug; // 親ページのスラッグを表示 $parent_title = get_post($parent_id)->post_title; // 親ページのタイトルを取得 echo $parent_title; // 親ページのタイトルを表示 echo get_permalink($parent_id); // 親ページの URL を表示 ?> |