Skip to content

Instantly share code, notes, and snippets.

@senooat
Last active November 28, 2017 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senooat/695603501ab7bc8306a1268ef45eb7b6 to your computer and use it in GitHub Desktop.
Save senooat/695603501ab7bc8306a1268ef45eb7b6 to your computer and use it in GitHub Desktop.
例)カスタム投稿タイプ「blog」をサムネイル付きで5件表示
<?php
$args = array(
'post_type' => 'blog',
'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 echo get_the_term_list( $post->ID, 'blog_cat' ); ?></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