Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <?php
  2. // 同一投稿者のページングを実現する
  3. $args = array(
  4. 'posts_per_page' => 1,
  5. 'orderby' => 'date',
  6. 'post_type' => 'post',
  7. 'post_parent' => "",
  8. 'author' => get_the_author_meta('ID'),
  9. 'post_status' => 'publish',
  10. 'suppress_filters' => true,
  11. );
  12.  
  13. // 前の記事を取得
  14. $args['order'] = 'DESC';
  15. $args['date_query'] = array(
  16. array(
  17. 'before' => get_the_time('Y/m/d H:i:s'),
  18. 'inclusive' => false,
  19. ),
  20. );
  21. $prev_post = false;
  22. $prev_posts = get_posts( $args );
  23. if(!empty($prev_posts) && isset($prev_posts[0])) {
  24. $prev_post = $prev_posts[0];
  25. }
  26.  
  27. // 次の記事を取得
  28. $args['order'] = 'ASC';
  29. $args['date_query'] = array(
  30. array(
  31. 'after' => get_the_time('Y/m/d H:i:s'),
  32. 'inclusive' => false,
  33. ),
  34. );
  35. $next_post = false;
  36. $next_posts = get_posts( $args );
  37. if(!empty($next_posts) && isset($next_posts[0])) {
  38. $next_post = $next_posts[0];
  39. }
  40.  
  41. // 前の記事表示
  42. if($prev_post) {
  43. $link = get_the_permalink($prev_post->ID);
  44. $title = get_the_title( $prev_post );
  45. $content = mb_strimwidth(wp_strip_all_tags($prev_post->post_content),0,150,"...");
  46. ?>
  47. <div class="col-sm-6">
  48. <div><small><i class="fa fa-chevron-circle-left"></i> 前の記事</small></div>
  49. <h3><a href="<?php echo $link;?>"><?php echo $title; ?></a></h3>
  50. <p><?php echo $content; ?></p>
  51. </div>
  52. <?php
  53. } else {
  54. ?>
  55. <div class="col-sm-6">
  56. <div><small><i class="fa fa-chevron-circle-left"></i> 前の記事</small></div>
  57. <h4>前の記事はありません</h4>
  58. </div>
  59. <?php
  60. }
  61.  
  62. // 次の記事表示
  63. if($next_post){
  64. $link = get_the_permalink($next_post->ID);
  65. $title = get_the_title( $next_post );
  66. $content = mb_strimwidth(wp_strip_all_tags($next_post->post_content),0,150,"...");
  67. ?>
  68. <div class="col-sm-6">
  69. <div class="text-right"><small>次の記事 <i class="fa fa-chevron-circle-right"></i></small></div>
  70. <h3 class="text-right"><a href="<?php echo $link;?>"><?php echo $title; ?></a></h3>
  71. <p><?php echo $content; ?></p>
  72. </div>
  73. <?php
  74. } else {
  75. ?>
  76. <div class="col-sm-6">
  77. <div class="text-right"><small>次の記事 <i class="fa fa-chevron-circle-right"></i></small></div>
  78. <h4 class="text-right">次の記事はありません</h4>
  79. </div>
  80. <?php
  81. }
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement