Wordpressでカスタム投稿タイプを設定して、固定ページごとにその投稿タイプに合う記事を一覧表示させようとしていますが、うまく表示されません。
固定ページごとにテンプレートを作って下記を記述しています。
いろいろ試したのですが、なんとかページャーを表示できたのが下記のコードです。
1ページに表示させる投稿は5件です。
その投稿テーマで7件の投稿をしているのに、2ページ目を見ても1ページ目と同じ内容の記事が5件表示されます。
どうしたら6件目以降を2ページ目以降にひょうじさせられるのでしょうか。
<?php /* 固定ページに記事一覧を表示する */ ?> <main class="<?php echo omega_apply_atomic( 'main_class', 'content' );?>" <?php omega_attr( 'content' ); ?>> <?php do_action( 'omega_before_content' ); do_action( 'omega_content' ); do_action( 'omega_after_content' ); ?> <?php /* post_type gallery はあなたのつけた名前に変更してください */ ?> <?php $loop = new WP_Query( array( 'post_type' => 'studies' ) ); while ( $loop->have_posts() && has_post_thumbnail() ) : $loop->the_post(); ?> <div class="gallery-post clearfix"> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to<?php the_title_attribute('class=postTitle'); ?>"><?php the_post_thumbnail('thumbnail', 'class=listImg'); ?><?php the_title(); ?></a> </p> <?php the_excerpt(); ?> </div> <?php endwhile; wp_reset_postdata(); ?> <?php /* ページャー */ ?> <?php $paged = ( get_query_var('paged')) ? get_query_var('paged') : 1; // query_posts("posts_per_page=5&paged=$paged&post_status=publish"); //非推奨なのでWP_Queryに置き換え $args = array( 'posts_per_page' => 5, 'paged' => $paged, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'studies', 'post_status' => 'publish', ); $the_query = new WP_Query($args); if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> <?php //ループ部分 endwhile; else: ?> <p><?php echo "お探しの記事、ページは見つかりませんでした。"; ?></p> <?php endif; ?> <?php //ページング if ($the_query->max_num_pages > 1) { echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%/', 'current' => max(1, $paged), 'total' => $the_query->max_num_pages )); } wp_reset_postdata(); ?> </main><!-- .content -->
回答1件
あなたの回答
tips
プレビュー