したいこと
WordPressでブログを作っています。
記事一覧ページにて、最新の記事は除外し2記事目からスタートして、
1ページあたり10記事を表示したいのですがどのようにしたら良いでしょうか?
query_postsは非推奨だと思うのでそれ以外の方法で考えていました。
index.php
php
1<?php 2//記事があればentriesブロック以下を表示 3if (have_posts()) : ?> 4 5<div class="entries"> 6 7<?php 8//記事数ぶんループ 9while (have_posts()) : 10the_post(); ?> 11 12 13<!-- エントリーアイテム(始) --> 14<a href="<?php the_permalink(); //記事のリンクを表示?>" class="entry-item wow fadeInUp"> 15<div class="entry-item-image"> 16<?php 17if (has_post_thumbnail()) { 18the_post_thumbnail('large'); 19} else { 20echo '<img src="' . esc_url(get_template_directory_uri()) . '/img/noimg.png" alt="">'; 21} 22?> 23</div> 24<div class="entry-item-meta"> 25 26<div class="entry-item-tag"><?php my_the_post_category(false); ?></div><!-- /entry-item-tag --> 27<time class="entry-item-published" datetime="<?php the_time('c'); ?>"><?php echo get_post_time('Y.n.j D'); ?></time><!-- /entry-item-published --> 28</div> 29<div class="entry-item-body"> 30<h2 class="entry-item-title"><?php the_title(); ?></h2> 31<div class="entry-item-excerpt"> 32<p class="entry-item-text"> 33<?php the_excerpt(); ?> 34</p> 35</div> 36</div> 37</a> 38<!-- エントリーアイテム(終) --> 39 40 41<?php endwhile; ?> 42 43</div> 44<!-- エントリーアイテム一式(終) --> 45<?php endif; ?>
試したこと
ループしたい内容の前後に下記の記述だと、2記事目から表示されるのですが、
ページネーションで次のページに飛んでも1ページ目と同じ10記事が表示されてしまいます。
ご教示のほど宜しくお願いいたします。
html
1<?php 2 $args = array( 3 'posts_per_page' => 10, 4 'offset' => 1, 5 ); 6 $posts = get_posts( $args ); 7 foreach ( $posts as $post ): 8 setup_postdata( $post ); 9?> 10 11<!-- ループしたい内容 --> 12 13<?php 14 endforeach; // ループの終了 15 wp_reset_postdata(); // 直前のクエリを復元する 16?>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/15 14:35
2020/08/15 14:58
2020/08/16 02:54
2020/08/16 04:17
2020/08/16 04:21
2020/08/16 05:13
2020/08/16 05:25