Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // 同一投稿者のページングを実現する
- $args = array(
- 'posts_per_page' => 1,
- 'orderby' => 'date',
- 'post_type' => 'post',
- 'post_parent' => "",
- 'author' => get_the_author_meta('ID'),
- 'post_status' => 'publish',
- 'suppress_filters' => true,
- );
- // 前の記事を取得
- $args['order'] = 'DESC';
- $args['date_query'] = array(
- array(
- 'before' => get_the_time('Y/m/d H:i:s'),
- 'inclusive' => false,
- ),
- );
- $prev_post = false;
- $prev_posts = get_posts( $args );
- if(!empty($prev_posts) && isset($prev_posts[0])) {
- $prev_post = $prev_posts[0];
- }
- // 次の記事を取得
- $args['order'] = 'ASC';
- $args['date_query'] = array(
- array(
- 'after' => get_the_time('Y/m/d H:i:s'),
- 'inclusive' => false,
- ),
- );
- $next_post = false;
- $next_posts = get_posts( $args );
- if(!empty($next_posts) && isset($next_posts[0])) {
- $next_post = $next_posts[0];
- }
- // 前の記事表示
- if($prev_post) {
- $link = get_the_permalink($prev_post->ID);
- $title = get_the_title( $prev_post );
- $content = mb_strimwidth(wp_strip_all_tags($prev_post->post_content),0,150,"...");
- ?>
- <div class="col-sm-6">
- <div><small><i class="fa fa-chevron-circle-left"></i> 前の記事</small></div>
- <h3><a href="<?php echo $link;?>"><?php echo $title; ?></a></h3>
- <p><?php echo $content; ?></p>
- </div>
- <?php
- } else {
- ?>
- <div class="col-sm-6">
- <div><small><i class="fa fa-chevron-circle-left"></i> 前の記事</small></div>
- <h4>前の記事はありません</h4>
- </div>
- <?php
- }
- // 次の記事表示
- if($next_post){
- $link = get_the_permalink($next_post->ID);
- $title = get_the_title( $next_post );
- $content = mb_strimwidth(wp_strip_all_tags($next_post->post_content),0,150,"...");
- ?>
- <div class="col-sm-6">
- <div class="text-right"><small>次の記事 <i class="fa fa-chevron-circle-right"></i></small></div>
- <h3 class="text-right"><a href="<?php echo $link;?>"><?php echo $title; ?></a></h3>
- <p><?php echo $content; ?></p>
- </div>
- <?php
- } else {
- ?>
- <div class="col-sm-6">
- <div class="text-right"><small>次の記事 <i class="fa fa-chevron-circle-right"></i></small></div>
- <h4 class="text-right">次の記事はありません</h4>
- </div>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement