[Solved] How to add css class to every second news article?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

[Solved] How to add css class to every second news article?

Post by urheat »

I have to have different CSS properties for every second news article. How this could be done? I would like to get following source code:

Code: Select all

<div class="NewsSummary Left">
...
</div>

<div class="NewsSummary Right">
...
</div>

<div class="NewsSummary Left">
...
</div>

and so on...
Last edited by urheat on Wed Jul 06, 2011 11:01 am, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: How to add css class to every second news article?

Post by Jos »

You might want to check example 7.10 on this page: http://www.smarty.net/docsv2/en/languag ... oreach.tpl
urheat
Forum Members
Forum Members
Posts: 243
Joined: Sat Oct 17, 2009 6:50 am

Re: How to add css class to every second news article?

Post by urheat »

Jos wrote:You might want to check example 7.10 on this page: http://www.smarty.net/docsv2/en/languag ... oreach.tpl
Thanks for the tip! But if you or someone else has already solution (maybe example code?) I would save a lot of time 'cause I'm not pro with smarty coding...
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: How to add css class to every second news article?

Post by Jos »

Code: Select all

{foreach from=$items item=entry name=newsentry}
<div class="NewsSummary {if $smarty.foreach.newsentry.index % 2 == 0}Left{else}Right{/if}">

</div>
{/foreach}
Don't forget to add the name=newsentry to the foreach statement.
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: How to add css class to every second news article?

Post by RonnyK »

I often use....

Code: Select all

{foreach from=$items item=entry}
{cycle values='row1,row2' assign='currow'}
<div class="NewsSummary {$currow}">
Ronny
Jos
Support Guru
Support Guru
Posts: 4020
Joined: Wed Sep 05, 2007 8:03 pm

Re: How to add css class to every second news article?

Post by Jos »

ah yes, cycle is also a nice function for this... forgot how simple things can be sometimes ;D
User avatar
micahgodbolt
Forum Members
Forum Members
Posts: 149
Joined: Thu Jul 29, 2010 11:09 pm

Re: How to add css class to every second news article?

Post by micahgodbolt »

Jos wrote:ah yes, cycle is also a nice function for this... forgot how simple things can be sometimes ;D
Where is the plus 1 button :)
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: How to add css class to every second news article?

Post by Wishbone »

pcfcopies wrote:Where is the plus 1 button :)
Image
uniqu3

Re: [Solved] How to add css class to every second news artic

Post by uniqu3 »

@Wishbone LOL can't click
Post Reply

Return to “CMSMS Core”