wordpress显示第二个三个帖子
wordpress display second three posts
我需要显示:
first three posts in first div from wordpress,
second three posts in second div from wordpress and
third three posts in third div from wordpress.
我该怎么做?
div 1
--1st post
--2nd tpost
--3rd post
div 2
--4th post
--5th post
--6th post
div 3
--7th post
--8th post
--9th post
您可以通过多种方法来完成。将数据放入一个数组,然后 chunk()
它,并循环遍历这些块。
或者,您可以简单地遍历数据:
<div class="...">
<?php
// Set counter
$i = 1;
// Loop over your posts
while (have_posts()) {
// If you have ouputted three already then close and reopen div
if ($i == 3) {
$i = 1;
echo '</div><div class="...">';
}
// Output the post and increment the counter
the_content();
$i++;
}
?>
</div>
希望代码对您有用。
<?php
$i=0;
if (have_posts() ) : while ( have_posts() ) : the_post();
if($i==0)
{
?>
<div><!--open div-->
<?php
}
?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<
$i++;
if($i==3)
{
$i=0;
?>
</div><!--closing div -->
<?php
}
endwhile; endif;
?>
我需要显示:
first three posts in first div from wordpress,
second three posts in second div from wordpress and
third three posts in third div from wordpress.
我该怎么做?
div 1
--1st post
--2nd tpost
--3rd post
div 2
--4th post
--5th post
--6th post
div 3
--7th post
--8th post
--9th post
您可以通过多种方法来完成。将数据放入一个数组,然后 chunk()
它,并循环遍历这些块。
或者,您可以简单地遍历数据:
<div class="...">
<?php
// Set counter
$i = 1;
// Loop over your posts
while (have_posts()) {
// If you have ouputted three already then close and reopen div
if ($i == 3) {
$i = 1;
echo '</div><div class="...">';
}
// Output the post and increment the counter
the_content();
$i++;
}
?>
</div>
希望代码对您有用。
<?php
$i=0;
if (have_posts() ) : while ( have_posts() ) : the_post();
if($i==0)
{
?>
<div><!--open div-->
<?php
}
?>
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<
$i++;
if($i==3)
{
$i=0;
?>
</div><!--closing div -->
<?php
}
endwhile; endif;
?>