indexページに特定の条件に当てはまる記事1件のみ掲載したい
-
indexページに以下の条件に当てはまる記事を掲載したいのですが、上手くいかないのでどなたかご教授いただけるとありがたいです。
・普段はカテゴリーIDが3かつ最新の記事を1件のみ表示
・先頭に固定表示にチェックを入れた場合、それがカテゴリーIDが3以外の記事でも優先的に表示(1件のみ)
・上記に当てはまる記事がない場合はヘッダーに入れ替えわかりにくいかもしれませんが、よろしくお願いします。
下記の状態だと、最新の記事のカテゴリーIDが3以外の場合にヘッダー表示になります。
$myquery_pickupにcat=>3を足してみましたが、先頭固定表示を入れた記事がカテゴリーID3以外だった場合に無視されてカテゴリーID3の最新記事になります。<?php $myquery_pickup = array( 'posts_per_page' => 1, 'ignore_sticky_posts' => 1, 'post__in' => get_option('sticky_posts') ); ?> <?php query_posts($myquery_pickup); ?> <?php if(have_posts()): while(have_posts()):the_post(); ?> <?php if(is_sticky()): ?> <?php if(has_post_thumbnail()) {the_post_thumnail();}else{echo '<img src="',get_template_directory_uri(),'/img/default.png" width="100%" height="100%">';} ?> <h2><?php the_title(); ?></h2> <p><?php the_content(); ?></p> <?php elseif(in_category(3)): ?> <?php if(has_post_thumbnail()) {the_post_thumnail();}else{echo '<img src="',get_template_directory_uri(),'/img/default.png" width="100%" height="100%">';} ?> <h2><?php the_title(); ?></h2> <p><?php the_content(); ?></p> </div> <?php else: ?> <img src="<?php header_image(); ?>" height="100%" width="100%"/> <?php endif; ?> <?php endwhile; endif; ;?>
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
- トピック「indexページに特定の条件に当てはまる記事1件のみ掲載したい」には新たに返信することはできません。