アイキャッチ及び投稿内容が連続してしまう
-
初めまして、いつも参考にさせて頂いております。
下記点について、ご教示頂けますでしょうか。【直近のイベント情報を指定件数表示したい (5 件の投稿)】
http://ja.forums.wordpress.org/topic/1756?replies=5上記URLにて、jim912 様が入力された function.php 及び content.php の構文を
無知なりにカスタマイズし、使用させて頂いているのですが、
見出しは各記事に対応したタイトルとなっているものの、
各記事のアイキャッチ画像と投稿内容(本文)が上手く表示されません。具体的にお話ししますと、カスタムフィールドにて date を作成し、開催日(Ymd)を入力、
本日日付から直近に開催されるイベント「記事A」「記事B」「記事C」を表示したいと考えています。
が、見出しは「記事A」「記事B」「記事C」のものが表示されるものの、
アイキャッチ・投稿内容は、全て「記事B」によるものとなってしまいました。他のページも参考にさせていただいたのですが、
いずれも私とは異なるご質問でしたので、新規にトピック作成をさせて頂きます。
PHP には疎いのですが、理解できるよう努めますので、ご回答を御願いします。
念の為、私にて編集した function.php 及び content.php を抜粋いたしますので、
ご確認を御願いいたします。function.php
//直近のイベント表示 function get_latest_events( $limit = 3 ) { global $wpdb; $today = date( 'Ymd' ); $limit = (int)$limit; $time_point = " AND ( ( b.meta_key = 'date' AND b.meta_value >= '$today' ) )"; $sql_head = " SELECT DISTINCT a.* FROM $wpdb->posts as a, $wpdb->postmeta as b WHERE a.ID = b.post_id AND a.post_type = 'post' AND a.post_status = 'publish' "; $sql_foot_base = " ORDER BY a.post_name LIMIT %d"; $sql_foot = $wpdb->prepare( $sql_foot_base, $limit ); $events = $wpdb->get_results( $sql_head . $time_point . $sql_foot ); if ( $limit > count( $events ) ) { $short = $limit - count( $events ); $sql_foot = $wpdb->prepare( $sql_foot_base, $short ); $has_start_meta = " AND b.meta_key = 'date' "; $next_year_events = $wpdb->get_results( $sql_head . $has_start_meta . $sql_foot ); if ( $events && $next_year_events ) { $event_ids = array(); foreach ( $events as $event ) { $event_ids[] = $event->ID; } foreach ( $next_year_events as $key => $next_year_event ) { if ( in_array( $next_year_event->ID, $event_ids ) ) { unset( $next_year_events[$key] ); } } } $events = array_merge( $events, $next_year_events ); } return $events; } function convert_event_day( $Ymd ) { if ( ! preg_match( '/^[\d]{4}$/', $Ymd ) ) { echo wp_specialchars( $Ymd ); return; } $month = ltrim( substr( $Ymd, 0, 2 ), '0' ); $day = ltrim( substr( $Ymd, 2, 2 ), '0' ); echo $month . '月' . $day . '日'; }
content.php
<?php $latest_events = get_latest_events(); if ( $latest_events ) : ?> <?php foreach ( $latest_events as $latest_event ) : $start_day = get_post_meta( $latest_event->ID, 'date', true ); $end_day = get_post_meta( $latest_event->ID, 'date', true ); $end_day = $end_day ? $end_day : $start_day; ?> <div class="post"> <h2><a href="<?php echo get_permalink( $latest_event->ID ); ?>" title="<?php echo attribute_escape( strip_tags( $latest_event->post_title ) ); ?>"><?php echo wp_specialchars( strip_tags( apply_filters( 'the_title', $latest_event->post_title ) ) ); ?></a> </h2> <p class="postcat"> <?php the_category(' '); ?> </p> <p class="thumb"> <?php if(has_post_thumbnail()): ?> <?php echo get_the_post_thumbnail(); ?> <?php else: ?> <img src="<?php bloginfo('template_url'); ?>/no_image.jpg" alt="No Image" width="150" height="150" /> <?php endif; ?> </p> <?php the_excerpt(); ?> <p class="more"><a href="<?php the_permalink(); ?>">詳細を確認する</a></p> </div> <?php endforeach; ?>
5件の返信を表示中 - 1 - 5件目 (全5件中)
5件の返信を表示中 - 1 - 5件目 (全5件中)
- トピック「アイキャッチ及び投稿内容が連続してしまう」には新たに返信することはできません。