※本記事は、Qiitaからの移行記事です。
使い方
functionに次項の内容を追記して、呼び出したいテンプレート上で以下のように記述します。
get_parents($page_id);
$page_id = 固定ページのページID
コード
function get_parents($page_id) { if (is_page($page_id)) { $tmp_pages = array(); $tmp_post_id = $page_id; while ($tmp_post_id <> 0) { $tmp_post = get_post($tmp_post_id); $tmp_pages[] = $tmp_post; $tmp_post_id = $tmp_post->post_parent; } $result = array_reverse($tmp_pages); return $result; } else { return false; } }