megane9988
7/21/2013 - 2:03 PM

アーカイブ用基本のループ

<!-- 記事があるかどうか -->
  <?php if (have_posts()): ?>
  <?php while ( have_posts() ) : the_post(); ?>

<!-- 全体をaでくくる -->
<a href="<?php the_permalink(); ?>" class="post-set">

<!-- アイキャッチのあるなし -->
      <?php if (has_post_thumbnail( $post_id = null )): ?>
        <p class="post_thumbnail">
          <?php the_post_thumbnail( $size = 'thumbnail', $attr = '' ); ?>
        </p>
      <?php else:?>
        <p class="post_thumbnail"><img src="http://dummyimage.com/150x150/000/fff" alt=""></p>
      <?php endif; ?>
<!-- 日付、タイトル、category -->
      <br>
      <?php echo get_the_date();?>
      <br>
      <?php echo the_title(); ?>
      <br>
        <?php
          $cat = get_the_category();
          $tmparray = array();
            foreach( $cat as $c ) 
              $tmparray[] = $c->cat_name;
              echo implode( ', ', $tmparray );
        ?>
      </a>
  <?php endwhile; ?>
  <?php else: ?>
  <!-- 記事がないとき -->
    記事がないお
  <?php endif; ?>