我正在使用以下代码以3so 3列和3行的列打印最后8篇发表的文章:
<?php
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 8,
\'paged\' => ( get_query_var(\'paged\') ? get_query_var(\'paged\') : 1)
);
query_posts($args);
$x = 0;
while (have_posts()) : the_post(); ?>
<?php if($x == 2) { ?>
<div class="portfolio_list_box portfolio_list_last">
<?php } else { ?>
<div class="portfolio_list_box">
<?php } ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(\'featured-home-portfolio\'); ?></a>
<a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
<?php the_excerpt(); ?>
</div><!--//portfolio_list_box-->
<?php if($x == 2) { echo \'<div class="clear"></div>\'; $x = -1; } ?>
<?php $x++; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
现在我想在第五篇文章后面放一张图片。这是第2行第3列。我修改了很多次这段代码,但我不能让这张图片只在第5篇文章之后显示出来。
我添加了以下内容:
<?php if($x == 2) { ?>
<div class="portfolio_list_box portfolio_list_last">
<?php } elseif($x == 5) { ?>
// image
<?php } else { ?>
但不起作用。如果有人能帮我解决这个问题,我真的很感激。谢谢