ダリの雑記:WEBプログラム版

固定ページの子ページを表示するショートコード【WordPress】

開いた固定ページの子ページが、自動的にリスト表示されるようにしたい場合、wp_list_pagesをショートコードにしてしまうと便利です。

functions.phpに下記を追記します。

[PHP]
function pageChild() {
global $post;

$args = array('depth' => 0,
'show_date' => NULL,
'date_format' => get_option('date_format'),
'child_of' => $post->ID,
'exclude' => NULL,
'include' => NULL,
'title_li' => '',
'echo' => 0,
'authors' => NULL,
'sort_column' => 'menu_order, post_title',
'link_before' => '',
'link_after' => '',
'exclude_tree' => '' );

$return = '

';

return $return;
}
add_shortcode('page_child', 'pageChild');
[/PHP]

子ページ持ちの固定ページに

[page_child]

と記述すると、その子ページがリスト表示されるようになります。

関数自体はなんてことないものですが、ショートコードって便利ですね。

モバイルバージョンを終了