Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
Last active December 21, 2015 06:18
Show Gist options
  • Save mypacecreator/6262960 to your computer and use it in GitHub Desktop.
Save mypacecreator/6262960 to your computer and use it in GitHub Desktop.
get_postsで投稿を取得してtableで出力し、奇数列偶数列にclassをつけてCSSでしましまにできるように
<table>
<tr>
<th>日付</th>
<th>タイトル</th>
</tr>
<?php
$postcount = 1; //奇数偶数をカウント
$news = get_posts( array(
'post_type' => 'type',
'posts_per_page' => -1,
));
foreach($news as $post) :
setup_postdata($post);
?>
<?php if ($postcount % 2 == 1): ?>
<tr <?php post_class('odd'); ?>>
<?php else: ?>
<tr <?php post_class('even'); ?>>
<?php endif; ?>
<td><?php the_time('Y.m.d'); ?></td>
<td><?php the_title(); ?></td>
</tr>
<?php
$postcount++; //投稿カウントを+1
endforeach;
wp_reset_postdata();
?>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment