Godfryd
Godfryd

Reputation: 479

PHP foreach cycle in separate divs

My PHP script's foreach cycle generates all blog articles information from database and then displays it in one place. I want each article information to be displayed in separate divs. How do I do it?

<div class="blog">
<?php if (count($articles)): foreach ($articles as $article): ?>
    <article><?php echo get_excerpt($article); ?><hr></article>
<?php endforeach; endif; ?>
</div>

Upvotes: 0

Views: 238

Answers (2)

Jorel Amthor
Jorel Amthor

Reputation: 1294

<div class="blog">
<?php if (count($articles)): foreach ($articles as $article): ?>
    <div><article><?php echo get_excerpt($article); ?><hr></article></div>
<?php endforeach; endif; ?>
</div>

Simply surrounds your articles with div's

Upvotes: 0

Vicky Gonsalves
Vicky Gonsalves

Reputation: 11717

Wrap your div inside foreach block

<div class="blog">
  <?php if (count($articles)): foreach ($articles as $article): ?>
    <div>
        <article><?php echo get_excerpt($article); ?><hr></article>
    </div>
  <?php endforeach; endif; ?>
</div>

Upvotes: 2

Related Questions