LoginSignup
3
3

More than 5 years have passed since last update.

WordPress固定ページに投稿一覧を表示して、ページングを表示する

Posted at

固定ページに投稿一覧を表示して、プラグインWP-PageNaviでページングを表示したい。
固定ページでは通常のコードで表示できないのです…汗

NGコード

<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>

解決コード

通常のコードに 'query' => $myposts という因数を渡すと解決できます。

page.php

<?php $paged = get_query_var('paged')? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
);
$myposts = new WP_Query($args);
if($myposts->have_posts()): while($myposts->have_posts()): $myposts->the_post();
?>
// 記事ループ
<p><?php the_title(); ?></p>

<?php endwhile; endif; wp_reset_postdata(); ?>

<?php
  if(function_exists('wp_pagenavi')) {
    wp_pagenavi(array('query' => $myposts));
  }
?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
pagenavi ここまで

参考サイト

固定ページに特定カテゴリーの投稿一覧を表示させる方法 | ワードプレステーマTCD
http://design-plus1.com/tcd-w/2015/12/custom01.html

WordPress小技集 – PageNaviを固定ページで使う –
http://program-designer.xyz/wordpress%E5%B0%8F%E6%8A%80%E9%9B%86-pagenavi%E3%82%92%E5%9B%BA%E5%AE%9A%E3%83%9A%E3%83%BC%E3%82%B8%E3%81%A7%E4%BD%BF%E3%81%86/

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3