前提・実現したいこと
WordPressでとあるメディアサイトを制作しているのですが、
記事一覧という固定ページの画面のみアイキャッチ画像が表示されないため、表示させたいです。
背景としては、依頼いただいた時点でトップページと同じように記事を表示させたいので、index.phpをコピーして改良したところ、
パーマリンクやアイキャッチ画像が表示されないという状況でした。
発生している問題
アイキャッチ画像がno imageとなり、クリックしても記事一覧のリンクに飛ぶようになってしまっています。
loop.php内のif(has_post_thumbnail()でfalseが返ってきてelseに入り、noimageが表示されていると思っています。
index.phpに関しては、HOMEページとなりましていわゆるTopページです。そちらでは表示されていてpage-article.phpになると表示されないというのが、疑問です。ifの条件等は見直したりはしたのですが、状況変わらずで詰まっています。
該当のソースコード(loop.php)
php
1 <?php 2 if(get_the_category()){ 3 $cat_meta = get_option("cat_meta_data"); 4 $cat = get_the_category(); 5 $cat_id = $cat[0]->cat_ID; 6 } 7 ?> 8 <article class="archiveItem 9 <?php if(get_option('fit_theme_articleLayout') == 'value2'): ?> archiveItem-wide<?php endif; ?> 10 <?php if(get_option('fit_theme_articleLayout') == 'value3'): ?> archiveItem-wideSp<?php endif; ?>"> 11 12 <div class="eyecatch eyecatch-archive"> 13 <?php if(is_sticky()):?> 14 <span class="eyecatch__ribbon">Pickup</span> 15 <?php endif;?> 16 <span class="eyecatch__cat bgc<?php if (isset($cat_meta[$cat_id])) { echo esc_html($cat_meta[$cat_id]);} ?> u-txtShdw"><?php the_category(' ');?></span> 17 <a href="<?php the_permalink(); ?>"><?php if(has_post_thumbnail()) {the_post_thumbnail('icatch');} else {echo '<img src="'.get_template_directory_uri().'/img/img_no.gif" alt="NO IMAGE"/>';}?></a> 18 </div>
該当のソースコード(page-article.php)
PHP
1<?php 2/** 3 * Template Name: 記事一覧 4 */ 5get_header(); ?> 6 7 <!-- l-wrapper --> 8 <div class="l-wrapper"> 9 <!-- l-main --> 10 <main class="l-main<?php if ( get_option('fit_theme_archiveLayout') == 'value2' ):?> l-main-single 11 <?php if ( get_option('fit_theme_singleWidth') == 'value2' ):?> l-main-w740<?php endif; ?> 12 <?php if ( get_option('fit_theme_singleWidth') == 'value3' ):?> l-main-w900<?php endif; ?> 13 <?php if ( get_option('fit_theme_singleWidth') == 'value4' ):?> l-main-w100<?php endif; ?> 14 <?php endif; ?>"> 15 16 <?php if (is_paged() ) : ?> 17 <?php dynamic_sidebar( 'top' ); ?> 18 <?php endif; ?> 19 20 <?php if (is_paged()) :?> 21 <header class="archiveTitle"> 22 <h2 class="heading heading-first"><?php show_page_number(''); ?>/<?php max_show_page_number(''); ?>ページ</h2> 23 <?php fit_sub_pagination(); ?> 24 </header> 25 <?php endif; ?> 26 <h2 class="top-heading">記事一覧</h2> 27 <?php if (have_posts()) : $count = 1; ?> 28 <div class="archive"> 29 <?php while (have_posts()) : the_post(); ?> 30 31 <?php get_template_part('loop');?> 32 33 <?php 34 $conditions = get_option('fit_ad_infeed'); 35 if(get_option('fit_ad_infeed1p')){ 36 $conditions = get_option('fit_ad_infeed') && is_paged(); 37 } 38 ?> 39 <?php if($conditions): ?> 40 <?php 41 $number = '1'; 42 if(get_option('fit_ad_infeedNumber')){ 43 $number = get_option('fit_ad_infeedNumber'); 44 } 45 ?> 46 <?php if($count == $number): ?> 47 <div class="archiveItem archiveItem-infeed 48 <?php if(get_option('fit_theme_articleLayout') == 'value2'): ?> archiveItem-wide<?php endif; ?> 49 <?php if(get_option('fit_theme_articleLayout') == 'value3'): ?> archiveItem-wideSp<?php endif; ?>"><?php echo get_option('fit_ad_infeed'); ?></div> 50 <?php endif; ?> 51 <?php $count = $count + 1; ?> 52 53 <?php endif; ?> 54 <?php endwhile; ?> 55 </div> 56 <?php else : ?> 57 <div class="archive"> 58 <div class="archiveList"> 59 <p class="archiveList__text archiveList__text-center">投稿が1件も見つかりませんでした。</p> 60 </div> 61 </div> 62 <?php endif; ?>
補足情報
テーマはLIONMEDIAとなります。
あなたの回答
tips
プレビュー