Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <ul>
  2. <?php
  3. //URLパラメータ取得
  4. $yget = isset($_GET['y']) ? htmlspecialchars($_GET['y']) : null;
  5.  
  6. //年度別アーカイブリスト
  7. $archives_year = strip_tags(wp_get_archives('type=monthly&show_count=0&format=custom&echo=0'));
  8. $archives_year = split("\n",$archives_year);
  9. $archives_year = preg_replace("/(\d{4})年1月/ue","'\\1'-1",$archives_year);
  10. $archives_year = preg_replace("/(\d{4})年2月/ue","'\\1'-1",$archives_year);
  11. $archives_year = preg_replace("/(\d{4})年3月/ue","'\\1'-1",$archives_year);
  12. $archives_year = preg_replace("/年\d{1,2}月/","",$archives_year);
  13. $archives_year = array_filter($archives_year);
  14. $archives_year = array_unique($archives_year);
  15. $archives_year = array_values($archives_year);
  16. if(empty($yget)){
  17. foreach($archives_year as $year_value){
  18. echo '<li><a href="'.home_url('/').'history/?y='.$year_value.'">'.$year_value.'年度</a></li>';
  19. }
  20. }
  21. ?>
  22. </ul>
  23.  
  24.  
  25. <?php //記事一覧
  26. if(!empty($yget)){ ?>
  27. <h2><?php echo $yget; ?>年度の記事一覧</h2>
  28. <dl>
  29. <?php
  30. $paged = get_query_var('paged') ? get_query_var('paged') : 1;
  31. $start = $yget.'/4/1';
  32. $end = ($yget+1).'/3/31 23:59:59';
  33. $args = array(
  34. 'post_type' => 'post',
  35. 'posts_per_page' => 10,
  36. 'paged' => $paged,
  37. 'date_query' => array(
  38. 'after' => $start,
  39. 'before' => $end,
  40. ),
  41. );
  42.  
  43. $the_query = new WP_Query( $args );
  44. if ( $the_query->have_posts() ) :
  45. while ( $the_query->have_posts() ) : $the_query->the_post();
  46. $date = get_the_date('Y-m-d');
  47. ?>
  48.  
  49. <dd><?php the_title(); ?>(<?php echo $date; ?>)</dd>
  50.  
  51. <?php
  52. endwhile;
  53. endif;
  54. ?>
  55. </dl>
  56. <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array('query' => $the_query)); } ?>
  57. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement