Wordpress > 投稿記事の最初の画像を取得

「Wordpress/投稿記事の最初の画像を取得」の編集履歴(バックアップ)一覧はこちら

Wordpress/投稿記事の最初の画像を取得 - (2013/02/05 (火) 21:36:34) の1つ前との変更点

追加された行は緑色になります。

削除された行は赤色になります。

**functions.phpに以下記述 #highlight(){{ function catch_that_image($prefix='',$postfix='') { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(!empty($first_img)){ return $prefix.$first_img.$postfix; } } }} **テンプレート内で呼び出す #highlight(){{ <?php echo catch_that_image('<img src="','" width="280px">'); ?> }}
**functions.phpに以下記述 #highlight(){{ function catch_first_image($prefix='',$postfix='') { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(!empty($first_img)){ return $prefix.$first_img.$postfix; } } }} **テンプレート内で呼び出す #highlight(){{ <?php $wp_query = new WP_Query( array( 'post_type' => array( 'report','information' ), 'posts_per_page' => 5 ) ); ?> <?php if (have_posts()) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <?php echo catch_first_image('<img src="','" width="280px">'); ?> }}  

表示オプション

横に並べて表示:
変化行の前後のみ表示: