Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:29:31+00:00 2026-06-11T07:29:31+00:00

I am using smarty and bootstrap, I am building an image gallery so my

  • 0

I am using smarty and bootstrap,

I am building an image gallery so my markup ends up being as posted below.

I know I can loop over my categories as {foreach $categories as $category}{/foreach}
But as you can see by the markup posted below I need to wrap the in groups of four.
That’s the part I don’t know how to do.

Also, note that there may not always be a multiple of four, e.g. there could be 15 categories.

How should I do this?

<div class="row-fluid">
    <ul class="thumbnails">
        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>

        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>
        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>
        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>
    </ul>
</div>

<div class="row-fluid">
    <ul class="thumbnails">
        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>
        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>
        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>

        <li class="span3">
            <div class="thumbnail">
                <a href="#" class="thumbnail"><img src="http://placehold.it/260x180" alt=""></a>

                <div class="caption">
                    <h3>Thumbnail label</h3>

                    <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida
                        at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>

                    <p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn">Action</a></p>
                </div>
            </div>
        </li>
    </ul>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:29:32+00:00Added an answer on June 11, 2026 at 7:29 am

    You can use name for the foreach loop and then check the iteration number, something like this:

    {foreach from=$array item=var name=myloop}
    
        {if $smarty.foreach.myloop.iteration % 4 == 1}
            {* this is the first in a group of four *}
        {elseif $smarty.foreach.myloop.iteration % 4 == 0}
            {* this is the last in a group of four *}
        {else}
            {* this is the second or the third *}
        {/if}
    
    {/foreach}
    

    Read through the documentation of foreach for more details. Specifically look at iteration and index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using smarty for my site, and I'm trying to loop through an array
How can I limit the amount of loops through an array using Smarty? Let's
How can I get the total number of items in an array using Smarty?
I'm building a CodeIgniter application and using Smarty as my templating system. Instead of
I found that using Smarty with PHP, sometimes extra time will need to be
I'm using Smarty templates which call object methods. I've put the code on a
I am using smarty tags with php and my question / issue is regarding
I am using CI + smarty + dojo framework in my one application. I
I'm using the last version of Smarty, I'm tring to register a block but
I am using Code Igniter, The HMVC library , and Smarty with this library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.