search.php
1 <div class="news-and-blog__list news-and-blog__list--news"> 2 <?php 3 $paged_news = (get_query_var('paged')) ? get_query_var('paged') : 1; 4 $args = array( 5 'post_type' => 'news-blog', 6 'posts_per_page' => 9, 7 'paged' => $paged_news, 8 'tax_query' => array( 9 array( 10 'taxonomy' => 'news-blog-category', 11 'field' => 'slug', 12 'terms' => 'news', 13 ), 14 ), 15 ); 16 $the_query_news = new WP_Query($args); 17 18 if ($the_query_news->have_posts()) { 19 while ($the_query_news->have_posts()) { 20 $the_query_news->the_post(); 21 ?> 22 <a href="<?php the_permalink(); ?>" class="news-and-blog__item"> 23 <?php 24 if (has_post_thumbnail()) { 25 the_post_thumbnail('newsblog-thumbnail'); 26 } else { 27 echo ""; 28 } 29 ?> 30 <p class="news-and-blog__cat">お知らせ</p> 31 <h1 class="news-and-blog__ttl"><?php the_title(); ?></h1> 32 <p class="news-and-blog__date"><?php the_time('Y.m.d'); ?></p> 33 </a> 34 <?php 35 } 36 wp_reset_postdata(); 37 } else { 38 echo '該当する投稿がありません'; 39 } 40 ?> 41 </div> 42 <div class="news__pager"> 43 <?php 44 $big = 999999999; 45 $current_page_news = max(1, get_query_var('paged')); 46 $total_pages_news = $the_query_news->max_num_pages; 47 48 if ($total_pages_news > 2) { 49 echo '<a href="' . esc_url(get_pagenum_link(1)) . '" class="pagination-link"><<</a>'; 50 } 51 52 echo paginate_links( 53 array( 54 'show_all' => false, 55 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 56 'format' => '?paged=%#%', 57 'current' => $current_page_news, 58 'total' => $total_pages_news, 59 'prev_text' => '<', 60 'next_text' => '>', 61 'mid_size' => 1, 62 'end_size' => 1, 63 'prev_next' => true, 64 'type' => 'list', 65 'add_args' => false, 66 'add_fragment' => '', 67 'before_page_number' => '', 68 'after_page_number' => '', 69 'before' => '<a class="pagination">', 70 'after' => '</a>', 71 'echo' => true, 72 ) 73 ); 74 75 if ($total_pages_news > 2) { 76 echo '<a href="' . esc_url(get_pagenum_link($total_pages_news)) . '" class="pagination-link">>></a>'; 77 } 78 79 if ($total_pages_news == 1) { 80 echo '<a href="' . esc_url(get_pagenum_link(1)) . '" class="pagination-link">1</a>'; 81 } 82 ?> 83 </div> 84 </div>
0 コメント