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

  • SEARCH
  • Home
  • 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 7763459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:39:53+00:00 2026-06-01T14:39:53+00:00

im having troubles with adding a class to the last option from foreach, its

  • 0

im having troubles with adding a class to the last option from foreach, its repeating it for some reason any ideas??

{if $subcategories} 
<div class="subcategories">
{if $subcategories|@count < 6}
    <ul>
{/if}
{foreach from=$splitted_subcategories item="ssubcateg"}
    {if $subcategories|count >= 6}
        <div class="subcategories">
            <ul>
    {/if}
        {foreach from=$ssubcateg item=category name="ssubcateg"}
        {if $category.category_id}<li{if $smarty.foreach.ssubcateg.last} class="last"{/if}><a href="{"categories.view?category_id=`$category.category_id`"|fn_url}" class="strong">{$category.category}</a></li>{/if}

    {/foreach}
    {if $subcategories|count >= 6}
            </ul>
        </div>
    {/if}
{/foreach}
{if $subcategories|count < 6}
</ul>
{/if}
</div>
{/if}

output:
seems to be repeating? and if there are 6 results is adds one class=”last” but the middle result as in 3rd result?

<ul> 
<li class="last"><a class="strong" href="#">Link</a></li>
    <li><a class="strong" href="#">Link</a></li>
    <li class="last"><a class="strong" href="#">Link</a></li>
    <li><a class="strong" href="#">Link</a></li>
</ul>
  • 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-01T14:39:54+00:00Added an answer on June 1, 2026 at 2:39 pm

    Your last item is repeating, because you’re checking for »being last in the inner looop«. you’re neglecting that the inner loop itself is looped. try:

    {foreach from=$splitted_subcategories item="ssubcateg" name="outer"}
      {foreach from=$ssubcateg item=category name="ssubcateg"}
        {if $smarty.foreach.outer.last && $smarty.foreach.ssubcateg.last}
          …
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Objective C and am having troubles adding a 2d int
I'm having trouble adding a static library from another Xcode project ( CloudApp API
I'm having some trouble with adding tips to a Request.HTML function. I have a
I'm having troubles finding a class name after extending other classes. Here are the
I'm having troubles keeping classes from being regenerated. I'm I have a schema A,
I'm having trouble adding any data to my database. It lets me modify entries
I'm having trouble adding a copy constructor to this class: http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html I need to
I'm having trouble adding a variable amount of labels to a panel. My problem
I'm having trouble adding Facebook Connect to my iPhone Project. Here's the directory structure:
I'm having trouble adding icons to jQuery UI's buttonset's.Adding icons to buttons work fine.Does

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.