博客文章布局wordpress

时间:2015-08-28 10:40:16

标签: php html wordpress blogs posts

我正在尝试在我的博客帖子页面上创建不同的布局,具体取决于帖子的创建时间。所以博客文章1将有一个类,而帖子2将有另一个,帖子3将有一个最后的类。很难解释,但这是我的代码,希望它会更有意义:

localhost

目前我的两个测试帖都显示为第一种类型的帖子,所以我认为我的计数器工作不正常,或者我的div在错误的位置使这项工作。我刚开始使用PHP,所以我不知道我哪里错了。任何建议都会很棒。

1 个答案:

答案 0 :(得分:0)

经过大约4个小时的研究和测试后,我发现了一个解决方案(credit):

<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) : ?>

 Add your Custom Post Divs Here for the 1st post. 

<?php elseif ($count == 2) : ?>      

 Add your Custom Post Divs Here for the 2nd post.          

<?php elseif ($count == 3) : ?> 

 Add your Custom Post Divs Here for the 3rd post.      

<?php elseif ($count == 4) : ?>  

 Add your Custom Post Divs Here for the 4th post.     

<?php else : ?>

 Add your Custom Post Divs Here for the rest of the posts. 

  <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

希望它可以帮助别人。