Post type by Year and Month

[eye_row data_bg_parallax_ratio=”0.5″ data_bg_size=”cover” data_bg_attachment=”scroll” data_bg_repeat=”no-repeat” data_bg_position=”top center” data_bg_type=”classic” data_margin_row=”0,0,0,0″ data_padding_row=”0,0,0,0″ data_gutters=”30px” data_col_nested=”no” data_container_fluid_xx_large=”100%” data_container_fluid_x_large=”100%” data_container_fluid_large=”100%” data_container_fluid_medium=”100%” data_container_fluid_small=”100%” data_container_fluid_extra_samll=”100%” data_cont=”fluid” data_shortcode_id=”ma97oylz2c”][eye_column data_width=”0-12-0″ data_desktop=”0″ data_tablet=”0″ data_mobile=”0″ data_offset_xl=”0″ data_offset_lg=”0″ data_offset_md=”0″ data_offset_sm=”0″ data_order_xl=”0″ data_order_lg=”0″ data_order_md=”0″ data_order_sm=”0″ data_bg_position=”top center” data_bg_repeat=”no-repeat” data_bg_attachment=”scroll” data_bg_size=”cover” data_bg_parallax_ratio=”0.5″ data_shortcode_id=”6uenjucia”][eye_image align=”none”]1150|https://codex.deshisoft.com/wp-content/uploads/2021/05/post-type-day-month-1024×227.jpg|large[/eye_image][eye_text shortcode_id=”1t8dien7ba” main_tab=”undefined” button_tab_right=”undefined” font_type=”system” font_devices=”undefined” size_xxl_type=”px” size_xxl_px=”1″ size_xl_type=”px” size_xl_px=”1″ size_lg_type=”px” size_lg_px=”1″ size_md_type=”px” size_md_px=”1″ size_sm_type=”px” size_sm_px=”1″ text_align=”left” font_line_height=”undefined” line_height_xxl_type=”px” line_height_xxl_px=”1″ line_height_xl_type=”px” line_height_xl_px=”1″ line_height_lg_type=”px” line_height_lg_px=”1″ line_height_md_type=”px” line_height_md_px=”1″ line_height_sm_type=”px” line_height_sm_px=”1″ font_letter_spacing=”undefined” letter_spacing_xxl_type=”px” letter_spacing_xxl_px=”1″ letter_spacing_xl_type=”px” letter_spacing_xl_px=”1″ letter_spacing_lg_type=”px” letter_spacing_lg_px=”1″ letter_spacing_md_type=”px” letter_spacing_md_px=”1″ letter_spacing_sm_type=”px” letter_spacing_sm_px=”1″ devices=”undefined” padding_row_xl=”0,15px,0,15px” padding_row_lg=”0,15px,0,15px” padding_row_md=”0,15px,0,15px” padding_row_sm=”0,15px,0,15px” bgopt=”undefined” bg_type=”classic” bg_position=”top center” bg_repeat=”no-repeat” bg_attachment=”scroll” bg_size=”cover” bg_parallax_ratio=”0.5″ heading_css=”undefined” heading_js=”undefined”]

<?php
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.taxonomy='category') INNER JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) WHERE $wpdb->terms.slug='blog' ORDER BY post_date DESC");
foreach($years as $year) : 
?>
<li><a href="JavaScript:void()"><?php echo $year; ?></a> 
<ul class="archive-sub-menu">
<? $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
foreach($months as $month) :
?>
<li><a href="<?php echo get_month_link($year, $month); ?>">
<?php echo date( 'F', mktime(0, 0, 0, $month) );?></a>
</li>
<?php endforeach;?>
</ul>
</li>
<?php endforeach; ?>

[/eye_text][/eye_column][/eye_row]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>