'post', 'posts_per_page' => -1, 'order' => 'DESC', 'orderby' => 'date', ) ); $current_month = ''; // Loop through all posts and group them by month. if ( $post_items->have_posts() ) { while ( $post_items->have_posts() ) { $post_items->the_post(); $the_month = get_the_date( 'F' ); $the_year = get_the_date( 'Y' ); // If no month is set yet, this is the first iteration; start a new group. if ( empty( $current_month ) ) { $current_month = $the_month; echo '
'; echo '

' . esc_html( $the_month . ' ' . $the_year ) . '

'; echo '
'; echo '
'; echo '

' . esc_html( $the_month . ' ' . $the_year ) . '

'; echo '
'; } wp_reset_postdata(); return ob_get_clean(); } /** * Registers a shortcode [binge_archive] that displays the archive. */ function brap_init_shortcodes() { add_shortcode( 'binge_archive', 'brap_display_posts_by_month' ); } add_action( 'init', 'brap_init_shortcodes' ); /** * Adds a small settings page under "Settings" to explain usage. */ add_action( 'admin_menu', 'brap_plugin_menu' ); function brap_plugin_menu() { add_options_page( __( 'Binge Reading Archive Settings', 'all-posts-archive-page' ), __( 'Binge Reading Archive', 'all-posts-archive-page' ), 'manage_options', 'all-posts-archive-page', 'brap_admin_page' ); } function brap_admin_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.', 'all-posts-archive-page' ) ); } ?>

[binge_archive]