条件分岐 アイキャッチ画像 indexphpでの扱い
-
お世話になっております。
トップページにて(index.php)特定のカテゴリ記事を4つ表示しております。
アイキャッチが登録されていない場合指定した画像を表示すると言うシンプルな挙動になります。
たくさんそれについて書かれたサイトはありましたし、そのコード単体ではちゃんと動きます。
しかし自身のphpにあてはめた時にエラーが起こってしまいます。<?php /** 省略 */ get_header(); ?> <div id="primary" class="content-area clr"> <div id="content" class="site-content left-content clr" role="main"> <?php if (!is_front_page()) { ?> <header class="page-header clr"> <h1 class="page-header-title"><?php echo get_the_title(get_option('page_for_posts', true)); ?></h1> </header><!-- .page-header --> <?php } ?> <?php query_posts("cat=8&showposts=4"); ?> <?php if (have_posts()): ?> <div id="blog-wrap" class="clr al-2"> <?php while (have_posts()): the_post(); ?> <!--ループ--> <div class="top_blogpost"> <article id="post-<?php the_ID(); ?>" > <?php // Display post thumbnail if (has_post_thumbnail() && get_theme_mod('wpex_blog_entry_thumb', '1') == '1') { ?> <!--動き--> <div class="view view-third"> <img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr(the_title_attribute('echo=0')); ?>" /> <?php } ?> <div class="mask"> <h2><?php the_title(); ?></h2> <?php if (wp_is_mobile()): ?> <p><?php if (get_theme_mod('wpex_entry_content_excerpt', 'excerpt') == 'content') { the_content(); } else { $wpex_readmore = get_theme_mod('wpex_blog_readmore') == '1' ? true : false; wpex_excerpt(30, $wpex_readmore); } ?></p> <?php else: ?> <p><?php if (get_theme_mod('wpex_entry_content_excerpt', 'excerpt') == 'content') { the_content(); } else { $wpex_readmore = get_theme_mod('wpex_blog_readmore') == '1' ? true : false; wpex_excerpt(60, $wpex_readmore); } ?></p> <?php endif; ?> <p class="time"><?php the_time('Y年m月d日'); ?></p> <a href="<?php the_permalink(); ?>" class="info">Read More</a> </div> </div> <!--動き--> </article><!-- .loop-entry --> </div> <!--ループ--> <?php endwhile; ?> </div><!-- #post --> <?php endif; ?> <div class="blog_b"> <a href="***.com/category/blog/" class="myButton_readmore">Read more blog</a> </div> </div><!-- #content --> <?php get_sidebar(); ?> </div><!-- #primary --> <?php get_footer(); ?>
上記phpで
<?php // Display post thumbnail if (has_post_thumbnail() && get_theme_mod('wpex_blog_entry_thumb', '1') == '1') { ?> <!--動き--> <div class="view view-third"> <img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr(the_title_attribute('echo=0')); ?>" />
にてアイキャッチが登録されていなければ
<img src="<?php echo wpex_get_featured_img_url(); ?>" alt="<?php echo esc_attr(the_title_attribute('echo=0')); ?>" />
を
デフォルトの画像を表示するようにしたいのです。
デフォルトの画像やまたは指定の画像表示自体は理解しております。
現在は何も登録しないと空白になりレイアウトが崩れてしまいます。画像がある時の該当箇所のHTMLは
<div class="top_blogpost"> <article id="post-367"> -------------------------------- <!--動き--> <div class="view view-third"> <img src="***.com/nekonote/wp-content/uploads/2016/10/1103_01-400x300.jpg" alt="タイトル"> -------------------------------- <div class="mask"> <h2>タイトル</h2> <p>説明文…</p> <p class="time">2016年11月10日</p> <a href="http://maki-maki.sakura.ne.jp/nekonote/%e3%83%86%e3%82%b9%e3%83%886-2-2-2-3-2/" class="info">Read More</a> </div> -------------------------------- </div> <!--動き--> -------------------------------- </article><!-- .loop-entry --> </div>
画像がない時は
<div class="top_blogpost"> <article id="post-834"> <div class="mask"> <h2>画像なしテスト</h2> <p>説明文…</p> <p class="time">2017年01月05日</p> <a href="***.com/%e7%94%bb%e5%83%8f%e3%81%aa%e3%81%97%e3%83%86%e3%82%b9%e3%83%88/" class="info">Read More</a> </div> </article></div>
となります。
長くなりましたがよろしくお願いいたします。
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「条件分岐 アイキャッチ画像 indexphpでの扱い」には新たに返信することはできません。