月別に区切りのある。著者投稿リンクの一覧表示

著者アーカイブページのサイドバーなどで、年月別に区切りをつけた、投稿リンク一覧を表示します

functions.php

function get_author_posts_group_month() {
 global $authordata, $post;

 $authors_posts= get_posts( array( 'author'=> $authordata->ID, 'post__not_in'=> array( $post->ID ), 'posts_per_page'=> -1, 'post_status' => 'publish' ) );
 $output = '<ul style="list-style:none;">';
 $y= '';
 $m= '';
 $html= '<li style="padding-left:30px"><a href="%1$s">%2$s</a></li>';

 foreach ( $authors_posts as $key=> $authors_post ) {

 preg_match( '!([0-9]+)-([0-9]+)-.*!', $authors_post->post_date, $args );

 if ( $y !== $args[1] ) {
$output .= '<li>' . absint( $args[1] ) . '</li>';
 }
 if ( $m !== $args[2] ) {
$output .= '<li>' . absint( $args[2] ) . '</li>';
 }
 $output .= sprintf( $html, 
 get_permalink( $authors_post->ID ),
 apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID )
 );

 $y= $args[1];
 $m= $args[2];
 }
 $output .= '</ul>';

 return $output;
}

テンプレートの必要な部分で、関数を呼び出します。

<?php echo get_author_posts_group_month(); ?>

[emulsion_relate_posts]