Hello guys,

I am using a Bootstrap grid with 6 element (As articles). 5 come directly from the database, and I need to add one more article element at the beginning, just for aesthetics. This is what I have so far. Any help is welcome. Thank you!

Here's the idea of what i need https://imgur.com/a/JTlROZ2

<?php $i = 0 ?>
<?php  START  LOOP ?>
<?php if($i % 2 == 0): ?> 
<div class="ps-box"><!-- POST -->
   <div class="row"><!-- ROW -->
      <?php endif; ?>
      <article>
         Element
      </article>
      <?php if($i % 2 != 0): ?>
   </div><!-- / ROW -->
</div><!-- / POST -->
<?php endif; ?>
<?php $i++ ?>

<?php END LOOP ?>

What is <?php START LOOP ?> ?? I assume it's some logic you have that loops through articles?

I'm having a hard time following your code because of your indenting.

I actually have to run in just a moment so I don't have much time to figure out what you're trying to do here ... my guess is that you want to use modular division so that when you loop through the articles, you increment $i each time. Then, if $i is even, open the div, and if $i is odd, close the div.

Does the code that you have do just that and work properly?

If so, at which point are you trying to add another article? Do you have data about the article? Why can't you just add it to the stack of articles that you are loopng through on line 2?

In other words, it sounds to me like the 6th article should be added by the controller, not the view.

Otherwise, you can change lines 7-9 to be something like:

<?php if ($i == 0): ?>
    <article> 6th Element </article>
<?php endif; ?>
<article>
    Element
</article>

That will inject the 6th element in at the beginning, before we increment $i.

commented: Dani, that worked pertect! Gracias! +0

Glad it worked. I'm going to mark this question solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.