Created
June 11, 2014 02:26
-
-
Save micalexander/9ff679d02a172a70ca43 to your computer and use it in GitHub Desktop.
wordpress:publish-date-accordion:snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| global $post; | |
| $post_backup = $post; | |
| $args = array( | |
| 'posts_per_page' => -1, | |
| 'post_type' => 'post-type-news', | |
| 'orderby' => 'date', | |
| 'order' => 'DSC' | |
| ); | |
| // Get the posts | |
| $query = new WP_Query($args); | |
| if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?> | |
| <?php | |
| $year = mysql2date('Y', $post->post_date); | |
| $month = mysql2date('F', $post->post_date); | |
| $day = mysql2date('j', $post->post_date); | |
| $post_by_months[$year][$month][] = array( 'post_date' => mysql2date('m/j/Y', $post->post_date), 'title' => $post->post_title , 'permalink' => get_permalink($post->ID) ); | |
| ?> | |
| <?php endwhile;?> | |
| <?php foreach ($post_by_months as $year => $months): ?> | |
| <h2><?php echo $year; ?></h2> | |
| <?php foreach ($months as $month => $items): ?> | |
| <div class="month-wrapper"> | |
| <h3><?php echo $month; ?></h3> | |
| <?php foreach ($items as $item): ?> | |
| <div class="permalink-wrapper"><a href="<?php echo $item['permalink']; ?>"><?php echo $item['post_date'] ?>: <?php echo wp_trim_words($item['title'], 7) ?></a></div> | |
| <?php endforeach ?> | |
| </div> | |
| <?php endforeach ?> | |
| <?php endforeach ?> | |
| <?php $args = array( | |
| 'base' => home_url() . '/news/%_%', | |
| 'format' => 'page/%#%/', | |
| 'total' => $wp_query->max_num_pages, | |
| 'current' => max( 1, $wp_query->query_vars['paged'] ), | |
| 'show_all' => true, | |
| //'end_size' => 1, | |
| //'mid_size' => 2, | |
| 'prev_next' => True, | |
| 'prev_text' => __('← Previous'), | |
| 'next_text' => __('Next →'), | |
| 'type' => 'plain', | |
| 'add_args' => False, | |
| 'add_fragment' => '' | |
| ); ?> | |
| <?php echo paginate_links( $args ) ; | |
| endif; | |
| $post = $post_backup; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment