WordPressのTwentySixteenテンプレートを使用しています。
特定カテゴリ(ID:7)のみ6記事取得し、リンク付きサムネイルをリスト表示し、さらにカルーセルとして表示させたいと考えています。
lang
1<div id="content" class="site-content"> 2[省略] 3---追記ここから--- 4<div id="topics_article"> 5<ul class="topics_article_carousel"> 6<?php $posts = get_posts('numberposts=6&category=7'); global $post; ?> 7<?php if($posts): foreach($posts as $post): setup_postdata($post); ?> 8<li> 9<a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> 10</li> 11<?php endforeach; endif; wp_reset_postdata(); ?> 12</ul> 13</div> 14---追記ここまで--- 15 <div id="primary" class="content-area"> 16 <main id="main" class="site-main clearfix" role="main"> 17 18 <?php if ( have_posts() ) : ?> 19 20 <?php if ( is_home() && ! is_front_page() ) : ?> 21 <header> 22 <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1> 23 </header> 24 <?php endif; ?> 25 26 <?php 27 // Start the loop. 28 while ( have_posts() ) : the_post(); 29 30 /* 31 * Include the Post-Format-specific template for the content. 32 * If you want to override this in a child theme, then include a file 33 * called content-___.php (where ___ is the Post Format name) and that will be used instead. 34 */ 35 get_template_part( 'content-child', get_post_format() ); 36 37 // End the loop. 38 endwhile; 39 40 // Previous/next page navigation. 41 the_posts_pagination( array( 42 'prev_text' => __( 'Previous page', 'twentysixteen' ), 43 'next_text' => __( 'Next page', 'twentysixteen' ), 44 'mid_size' => 6, 45 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>', 46 ) ); 47 48 // If no content, include the "No posts found" template. 49 else : 50 get_template_part( 'template-parts/content', 'none' ); 51 52 endif; 53 ?> 54 55 </main><!-- .site-main --> 56 </div><!-- .content-area -->
上記のように追記しました。
#topics_article
タグ内の記事取得は意図の通りに動いているようですが、
#main
タグ内の記事取得にも干渉してしまっているようで、
なぜか#main
タグ内の取得記事一覧でも
ID:7のカテゴリ記事しか取得されないようになってしまいました。
こちらを、#main
タグ内はデフォルトのように
全カテゴリの記事を取得したいのですが、どのように表記すればいいのでしょうか?
WordPress、jQuery、PHPについては勉強中の身です。
ご回答よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/01 03:37