我使用WordPress主题的基础,我需要用“行”类把两个帖子打包成一个div。问题是我需要把div class=“row”放在第一篇文章之前,然后用div关闭第二篇文章,并且它应该在每一篇新文章中重复。
这是我的密码:
<?php query_posts( 'cat=2&showposts=9&orderby=date&order=DESC' ); ?>
<div <?php post_class('small-12 medium-6 large-6 columns') ?> id="post-<?php the_ID(); ?>">
<?php echo '<a href="', get_permalink(), '">';
if ( has_post_thumbnail() ) {the_post_thumbnail();}
else { echo '<img src="', get_template_directory_uri( 'template_directory' ), '/images/thumb-default.png','" alt="" />'; }
echo '</a>';
?>
<a href="<?php echo get_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
<p><?php echo get_excerpt(); ?></p>
</div>
我想是这样的
<?php
$count = 1;
$outputstring = "";
ur while loop
if ( $count % 2 != 0 )
{
$outputstring .= " <row div>";
}
$outputstring .= "<div" . post_class('small-12 medium-6 large-6 columns'). ' id="post-'. the_ID() .'>';
YOUR OUTPUT CODE HERE
if ( $count % 2 == 0 )
{
$outputstring .= " </end row div>";
}
$count++;
END your while loop
echo $outputstring; /// here is where u output the WHOLE thing outside of your loop
?>