固定ページで特定のカテゴリーの投稿記事一覧を表示させるには?
-
初心者です。
既存のテーマを使って一部カスタマイズしています。
固定ページ(page-lesson.php)で、あるカテゴリーの投稿記事のみを表示させたいのですが、WP_Queryでもget_postsでもうまくいきません。get_postsではエラーで真っ白画面になり、WP_Queryでは記事が一件しか表示されません。
どのコードが間違っているのでしょうか?get_postsのコード
<div class="lesson-post"> <?php $args = array( ‘category’ => 2; ‘post_type’ => ‘post’; 'posts_per_page' => -1 ; $lesson_posts = get_posts( $args ); foreach ($lesson_posts as $post ) : setup_postdata( $post ); ?> <article id="post"> <div class="entry"> <div class="lesson-text"> <h3><?php the_title(); ?></h3> <p><?php the_content() ?></p> </div> </div><!-- .entry --> </article><!-- #post --> <?php endforeach; wp_reset_postdata(); ?> </div>
WP_Queryのコード
<div class="span_12"> <?php $wp_query = new WP_Query(); $my_posts = array( 'post_type' => 'post', 'category_name' => ‘lesson’, 'posts_per_page'=> ‘4’, ); $wp_query->query( $my_posts ); if( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <div class="col boxed lesson-post"> <?php get_template_part('content','lesson') ?> </div><!-- lesson-post --> <?php endwhile; endif; wp_reset_postdata(); ?> </div>
どなたか、お教え願えれば!! どうぞよろしくお願いいたします。
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
- トピック「固定ページで特定のカテゴリーの投稿記事一覧を表示させるには?」には新たに返信することはできません。