記事が1件も無い場合に文字を表示させる方法
-
カスタム投稿タイプ(event)でカテゴリー名(typea)の記事を5件取得し
その記事の中のカスタムフィールドテンプレートに「サイトurl」が入った場合と「本文」が入った場合で条件分岐して【画像とタイトルリンク】を表示するようにしています。これに追加して
カスタム投稿タイプ(event)でカテゴリー名(typea)の記事が1件も無い場合に「イベント情報はありません」を表示させる方法が知りたいのです。<div id="event"> <h2>イベント</h2> <?php query_posts(array('category_name' => 'typea', 'post_type' => array('event'), 'posts_per_page' => 5)); ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <!--<?php if ( post_custom('サイトURL') ) : ?>--> <div class="entrybox"> <div class="eventphoto"> <?php $attach_id = get_post_meta($post->ID,"画像",true); $image_info = wp_get_attachment_image_src( $attach_id , 'full' ); list( $url, $w, $h) = $image_info; $h = intval(200 * ( $h / $w )); $alt = get_post_meta($attach_id , '_wp_attachment_image_alt', true); ?> <a href="<?php echo post_custom('サイトURL'); ?>" title="<?php the_title(); ?>の詳細へ" target="_blank"> <img class="zzzz" src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" width="100px" height="75px" /></a> <!-- /.eventphoto --></div> <div class="eventte"> <?php if (function_exists('get_cat_icon')) get_cat_icon('link=false'); ?> <?php echo post_custom('開催日'); ?><br><a href="<?php echo post_custom('サイトURL'); ?>" title="<?php the_title(); ?>の詳細へ" target="_blank"> <?php the_title(); ?></a> <!-- /.eventte --></div> <div style="clear:both;"></div> <!-- /.entrybox --></div> <?php elseif( post_custom('本文') ) : ?> <div class="entrybox"> <div class="eventphoto"> <?php $attach_id = get_post_meta($post->ID,"画像",true); $image_info = wp_get_attachment_image_src( $attach_id , 'full' ); list( $url, $w, $h) = $image_info; $h = intval(200 * ( $h / $w )); $alt = get_post_meta($attach_id , '_wp_attachment_image_alt', true); ?> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>の詳細へ"> <img class="zzzz" src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" width="100px" height="75px" /></a> <!-- /.eventphoto --></div> <div class="eventte"> <?php if (function_exists('get_cat_icon')) get_cat_icon('link=false'); ?> <?php echo post_custom('開催日'); ?><br> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>の詳細へ"><?php the_title(); ?></a> <!-- /.eventte --></div> <div style="clear:both;"></div> <!-- /.entrybox --></div> <?php endif; ?> <?php endwhile; endif; ?> <!-- /#event --></div>
ご教授いただけますと本当に助かります。よろしくお願いします。
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「記事が1件も無い場合に文字を表示させる方法」には新たに返信することはできません。