任意のタグが登録されている記事を一覧(アイキャッチ画像も)
TOPページなど、ループ外で表示するコードです
<?php
~ここに以下のコードを書く
?>
$arg = array( 'posts_per_page' => 4, // 表示する件数 'orderby' => 'date', // 日付でソート 'order' => 'DESC', // DESCで最新から表示、ASCで最古から表示 'tag' => 'pickup' // 表示したいタグのスラッグを指定 ); $posts = get_posts( $arg ); foreach ( $posts as $post ) : setup_postdata( $post ); $my_excerpt = get_the_excerpt(); if ( has_post_thumbnail( $post->ID ) ) { $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo '<div class="tagimg col-xs-12 col-sm-4 col-md-4 col-lg-4">'; $tag = get_the_tags(); echo '<a href="'. get_category_link($tag[0]->term_id) .'">'; //echo '<a href="' . $full_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" target="_blank">'; echo get_the_post_thumbnail($post->ID, 'full'); echo '</a>'; //記事のタイトルとリンク echo '<h3><a href="'. get_the_permalink() .'">' . get_the_title() . '</a></h3>'; //記事の抜粋 echo '<p>' .$my_excerpt .'</p>'; echo '</div>'; echo "\n"; } endforeach; wp_reset_postdata();