I want to add my ul & li loop.. Example
Let's say I have infinite posts and I want the result should be like this
<ul>
<li>Title 1 - content 1</li>
<li>Title 2 - content 2</li>
<li>Title 3 - content 2</li>
</ul>
<ul>
<li>Title 3 - content 3</li>
<li>Title 4 - content 4</li>
</ul>
<ul>
<li>Title 1 - content 1</li>
<li>Title 2 - content 2</li>
<li>Title 3 - content 2</li>
</ul>
<ul>
<?php $i=1; foreach ($posts as $post): ?>
<li> <?php echo $i; ?>
<div class="postWrapper">
<div class="post_details">
<?php if($post->getFeaturedImage()): ?>
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage(); ?>" width="245" height="417">
<?php endif; ?>
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
<?php if($post->getSubTitle()):
echo '<p class="sub_title">'.$post->getSubTitle().'</p>';
endif;
?>
</div>
</div>
</li>
<?php $i++; endforeach; ?>
</ul>
答案 0 :(得分:0)
<ul class="blog-grid3">
<?php
$k = 3;
$j = 0;
$i = 1;
foreach ($posts as $post):
?>
<li>
<div class="postWrapper">
<div class="post_details">
<?php if($post->getFeaturedImage()): ?>
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$post->getFeaturedImage(); ?>" width="245" height="417">
<?php endif; ?>
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
<?php if($post->getSubTitle()):
echo '<p class="sub_title">'.$post->getSubTitle().'</p>';
endif;
?>
</div>
</div>
</li>
<?php
$j++;
if($k==$j){
if($k==3){
$k = 2;
}else{
$k = 3;
}
$j = 0;
}
if($j == 0 and $i!=count($posts)){
?>
</ul>
<ul class="blog-grid<?php echo $k;?>">
<?php
}
$i++;
endforeach;
?>
</ul>