Last active
December 21, 2015 06:18
-
-
Save mypacecreator/6262960 to your computer and use it in GitHub Desktop.
get_postsで投稿を取得してtableで出力し、奇数列偶数列にclassをつけてCSSでしましまにできるように
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
<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