<ul> <?php wp_list_categories(array('title_li' => '', 'taxonomy' => 'topicslist', 'show_count' => 0, 'depth' => 1)); ?> </ul>
taxonomy’ => ‘topicslist’, // カスタム分類名
2.カスタム分類の最新記事を表示件数を指定して表示
<ul> <?php $args = array( 'post_type' => 'topics', 'taxonomy' => 'topicslist', 'posts_per_page' => 10, 'numberposts' => '-1', ); $my_posts = get_posts($args); foreach ( $my_posts as $post ) { setup_postdata($post); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php } ?> </ul>
まずfunctions.phpに下記を追加
<?php global $my_archives_post_type; add_filter( 'getarchives_where', 'my_getarchives_where', 10, 2 ); function my_getarchives_where( $where, $r ) { global $my_archives_post_type; if ( isset($r['post_type']) ) { $my_archives_post_type = $r['post_type']; $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where ); } else { $my_archives_post_type = ''; } return $where; } add_filter( 'get_archives_link', 'my_get_archives_link' ); function my_get_archives_link( $link_html ) { global $my_archives_post_type; if ( '' != $my_archives_post_type ) $add_link .= '?post_type=' . $my_archives_post_type; $link_html = preg_replace("/href=\'(.+)\'\s/","href='$1".$add_link." '",$link_html); return $link_html; } ?>
sidebar.phpの出力したい場所に下記を追加
<ul> <?php wp_get_archives('type=monthly&post_type=topics'); ?> </ul>
type=monthly&post_type=カスタムタイプ名
5.カスタム投稿の年別アーカイブを表示
Custom Post Type Permalinksのプラグインを入れておくと下記のテンプレートタグだけで出力できます。
<?php wp_get_archives(array('post_type' => 'gallery', 'type' => 'yearly')); ?>
post_type’ => ‘gallery’ // 投稿タイプ名