Last active
November 28, 2017 01:00
-
-
Save senooat/11562b4085cdf6871e0e2f62ff051c22 to your computer and use it in GitHub Desktop.
例)カテゴリー「news」をサムネイル付きで5件表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'category_name' => 'news', | |
'posts_per_page' => '5' | |
); | |
$the_query = new WP_Query($args); | |
if($the_query->have_posts()): | |
echo '<ul>'; | |
while ($the_query->have_posts()) : $the_query->the_post(); | |
?> | |
<li> | |
<figure> | |
<?php if (has_post_thumbnail()) : ?> | |
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a> | |
<?php else : ?> | |
<a href="<?php the_permalink(); ?>"><img src="http://placehold.jp/150x150.png" width="150" height="150" alt="" /></a> | |
<?php endif ; ?> | |
</figure> | |
<span><?php the_time('Y-m-d'); ?></span> | |
<span><?php the_category(); ?></span> | |
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> | |
<p><?php the_content(); ?></p> | |
</li> | |
<?php | |
endwhile; | |
echo '</ul>'; | |
endif; | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment