<div class="side_archive_menu">
<?php
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month ,
YEAR( post_date ) AS year,
COUNT( id ) as post_count FROM $wpdb->posts
WHERE post_status = 'publish' and post_date <= now( )
and post_type = 'post'
GROUP BY month , year
ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year;
if ($year_current != $year_prev){
if ($year_prev != null){?>
<?php } ?>
<p class="toggle_btn"><?php echo $month->year; ?>年</p>
<ul class="child">
<?php } ?>
<li>
<a href="<?php bloginfo('url') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>">
<?php echo date("n", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>月
(<?php echo $month->post_count; ?>)
</a>
</li>
<?php $year_prev = $year_current;
endforeach; ?>
</ul>
</div>
<!-- /.side_archive_menu -->
<div class="side_archive_menu">
<p class="toggle_btn">2018年</p>
<ul class="child">
<li><a href="">11月(1)</a></li>
<li><a href="">10月(14)</a></li>
<li><a href="">9月(1)</a></li>
</ul>
</div>
<!-- /.side_archive_menu -->
.child {
display: none;
}
$(".toggle_btn").on("click", function() {
$(this).next().slideToggle();
$(this).toggleClass("active");
});
add_action(
'init',
function() {
remove_post_type_support( 'ポストタイプ名', 'editor' );
},
99
);
<?php
/*
----------------------------------------------------------------------
widgetの設定があれば表示
----------------------------------------------------------------------
*/
if ( is_active_sidebar( 'sidebar1' ) ) {
dynamic_sidebar( 'sidebar1' );
}
?>
<?php wp_get_archives( 'type=monthly&post_type=ポストタイプ名' ); ?>
<?php if ( has_post_thumbnail() ) : /* もしアイキャッチが登録されていたら */ ?>
<img class="lazy" src="<?php echo esc_url( $my_template_url ); ?>/img/dummy-lazy.png" data-src="<?php the_post_thumbnail_url(); ?>" alt="<?php echo esc_html( the_title() ); ?>">
<?php else : /* 登録されていなかったら */ ?>
<img class="lazy" src="<?php echo esc_url( $my_template_url ); ?>/img/dummy-lazy.png" data-src="<?php echo esc_url( $my_template_url ); ?>/img/dummy-photo.png" alt="<?php echo esc_html( the_title() ); ?>">
<?php endif; ?>