32:投稿詳細に前後記事リンクを表示する
公開日:2018年11月06日
更新日:2018年11月14日
投稿詳細ページに前後の投稿へのリンクを表示させます。
single.php
<?php get_header(); ?>
<div class="content">
<div class="main">
<div class="main-loop">
<div class="inner">
<?php /***** メインループ開始 *****/ ?>
<?php if (have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<?php $id = get_the_ID(); ?>
<?php // テンプレートパーツ読み込み:一覧 ?>
<?php get_template_part('content','single'); ?>
<?php // 前後記事リンク ?>
<div class="pagination-single">
<p class="prev"><?php previous_post_link('%link'); ?></p>
<p class="next"><?php next_post_link('%link'); ?></p>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php // テンプレートパーツ読み込み:記事なし ?>
<?php get_template_part('content','none'); ?>
<?php endif; ?>
<?php /***** メインループ終了 *****/ ?>
</div><!-- /.inner -->
</div><!-- /.main-loop -->
</div><!-- /.main -->
<?php get_sidebar(); ?>
</div><!-- /.content -->
<?php
get_footer();
style.css
.pagination-single {
display: flex;
justify-content: space-between;
}
このページで出てくる関数
WordPress関数は「公式サイトのドキュメント」で確認しましょう。
WordPress関数
get_header()
have_posts()
the_post()
get_the_ID()
get_template_part()
previous_post_link()
next_post_link()
get_sidebar()
get_footer()
オリジナル関数
getThumbnail()
getCatLinkList()
getTagLinkList()
欠席者対応:wireframe12
同じタグのコンテンツ
同じカテゴリーのコンテンツ