投稿日:2017/06/13
更新日:2018/03/05
EPRESSの仕様で固定ページに設定されているサブタイトル。
これをサイトマップに表示させたいとき。
カテゴリページは見ていただいたらわかるとおり、値を取得してhtmlと
結合して表示させています。
なので固定ページもこのやり方を使ってサブタイトルを表示させる。 /wp-content/themes/epressのテーマ/functions/module/sitemap.php
http://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/get_pages
固定ページ情報取得
これをサイトマップに表示させたいとき。
- 原始的なやり方
- 少しかっこいいやり方
原始的なやり方
固定ページは wp_list_pages を使ってhtmlを生成していますがカテゴリページは見ていただいたらわかるとおり、値を取得してhtmlと
結合して表示させています。
なので固定ページもこのやり方を使ってサブタイトルを表示させる。 /wp-content/themes/epressのテーマ/functions/module/sitemap.php
if( !function_exists('epress_sitemap') ){
function epress_sitemap($type='pages'){
if( $type === 'pages' ){
$pageargs = array(
'sort_column' => 'menu_order',
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages( $pageargs );
foreach ($pages as $page) { ?>
<li>
<a href="/<?=$page->post_name ?>"><?=$page->post_title ?><?= get_field('subtitle', $page->ID); ?>
</a>
</li>
<?php }
}else if( $type === 'categories' ){ ?>
//以下略
get_pages()http://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/get_pages
固定ページ情報取得
'sort_column' => 'menu_order',
固定ページ順に表示する。