RSSで複数のサイトのWordPressの記事を表示しようと考えています。
サムネイルの画像の上に10日間NEWを表示するというプログラムを考えているのですが。
現在の時刻の取得の仕方と投稿日の取得の仕方が分かりません。
参考記事
https://www.puzzle-web.jp/archive/1520/
https://www.webernote.net/wordpress/wp-rss.html
お力を頂けると幸いです。
<?php include_once( ABSPATH . WPINC . '/feed.php' ); $rss = fetch_feed( array( 'ほげほげ', 'ほげほげ' ) ); if ( !is_wp_error( $rss ) ) { $maxitems = $rss->get_item_quantity( 12 ); $rss_items = $rss->get_items( 0, $maxitems ); } ?> <?php if ( !empty( $maxitems ) ) : ?> <?php if ($maxitems == 0) echo '<li>RSSデータがありませんでした.</li>'; else foreach ( $rss_items as $item ) : ?> <?php $days = 10; $today = date_i18n( 'U' );//取得方法? $entry = get_the_time( 'U' );//取得方法? $elapsed = date( 'U', ( $today - $entry ) ) / 86400; if ( $days > $elapsed ) { echo '<div class="new_bg"><span class="new">New</span></div>'; } ?> <div class="post_photo"> <div class="new_bg"> <span class="new">New</span> </div> <a href="<?php echo $item->get_permalink(); ?>"> <?php $first_img = ''; if ( preg_match( '/<img.+?src=[\'"]([^\'"]+?)[\'"].*?>/msi', $item->get_content(), $matches ) ) { $first_img = $matches[1]; } ?> <?php if ( !empty( $first_img ) ) : ?> <img src="<?php echo esc_attr( $first_img ); ?>" class="news-thumbnail"/> <?php endif; ?> </a> </div> <a href="<?php echo $item->get_permalink(); ?>" class="news-title"> <?php echo $item->get_title();// タイトル ?> </a> <span class="date"> <?php echo $item->get_date('Y.m.d');// 日付 ?> </span> <span class="desc"> <?php echo mb_substr(strip_tags($item->get_description()), 0, 50);// 抜粋記事の文字数を指定 ?> ... <a href='<?php echo $item->get_permalink(); ?>' target="_blank">続きを読む</a> </span> </div> <?php endforeach; ?> <?php endif; ?>
あなたの回答
tips
プレビュー