プラグイン(PS Auto Sitemap)を使わずにサイトマップを生成させるようにした。
やはりデザインが思い通りに作れるので良い。アップデートとかも気にせずに使えるし。
とにかくできるだけ、プラグインを使わないようにしていきたい。
以下の参考サイトからコードを使わせていただきました。
ありがとうございますm(__)m
参考サイト:
プラグイン無しでサイトマップページを作るメモ
【sitemap.php】
<div class="sitemap-top"> <a href="<?php echo esc_url( home_url( '/' ) ); ?>">ホーム</a> </div> <?php /******************** post ********************/?> <?php $args = array( 'post_type' => array( 'post' ), ); $query = new WP_Query( $args ); if( $query->have_posts() ){ ?> <div class="sitemap-tree post-sitemap-tree"> <ul> <?php $countwithlink = wp_list_categories(array( 'title_li' => '', 'show_count' => 1, 'hide_empty' => 1, 'use_desc_for_title' => 0, 'hierarchical' => 1, 'current_category' => 0, 'pad_counts' => 0, 'walker' => null, 'show_option_none' => '', 'echo' => 0 )); $countwithlink = preg_replace('/<\/a> (\([0-9]*\))/', ' $1</a>', $countwithlink); $countwithlink = str_replace('(0)', '', $countwithlink); echo $countwithlink; ?> </ul> <?php } wp_reset_postdata(); ?> </div><!-- singles--> <?php /******************** custom post ********************/?> <?php $args = array( 'public' => true,/* 公開された(publicな)投稿タイプのみ */ '_builtin' => false,/* デフォルトの投稿タイプを除外 */ ); $output = 'names'; $operator = 'and';/* 'and' or 'or' */ $post_types = get_post_types( $args, $output, $operator ); foreach( $post_types as $post_type ){ $taxonomies = get_taxonomies( array( 'object_type' => array( $post_type ) ) ); foreach( $taxonomies as $tax ){ $args = array( 'title_li' => '', 'show_count' => 1, 'hide_empty' => 1, 'use_desc_for_title' => 0, 'hierarchical' => 1, 'current_category' => 0, 'pad_counts' => 0, 'post_type' => $post_type, 'taxonomy' => $tax, 'walker' => null, 'show_option_none' => '' ); $query = new WP_Query( $args ); if( $query->have_posts() ){ ?> <div class="sitemap-tree post-sitemap-tree"> <ul> <?php wp_list_categories( $args ); ?> </ul> </div> <?php } wp_reset_postdata(); break; } } ?> <?php /******************** pages ********************/?> <?php $ex_pages = [ 'post_type' => 'page', 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => '-1' ]; $query = new WP_Query( $ex_pages ); $ex_id = ''; if( $query->have_posts() ){ while( $query->have_posts() ){ $query->the_post(); $title = get_post()->post_name; if( strstr( $title, 'home' ) || strstr( $title, 'result' ) || strstr( $title, 'results' ) || strstr( $title, 'confirm' ) || strstr( $title, 'error' ) || strstr( $title, 'arg' ) || strstr( $title, 'sitemap' ) ){ $ex_id .= get_post()->ID . ','; } } $args = [ /*'show_home' => 'トップページ',*/ 'menu_class' => 'sitemap-tree-pages', 'container' => '', 'sort_column' => 'menu_order', 'exclude' => $ex_id, ]; echo '<div class="sitemap-tree page-sitemap-tree">'; wp_page_menu( $args ); echo '</div>'; } wp_reset_postdata(); ?>