Page 1 of 1

Different css class on every other news item?

Posted: Thu Aug 10, 2006 8:27 pm
by RazorMedia
Hope i´m the right forum..

I want every other news item to have a different style. Is it possible to modify the news module so that every other news item gets a different class?

Like this: http://www.emerfoto.nu/new/

Re: Different css class on every other news item?

Posted: Thu Aug 10, 2006 10:13 pm
by tsw
havent actually looked at news template as Im heading to bed but if it uses smarty foreach loop you can use smarty cycle

pseudo:

Code: Select all

{foreach ...}
  class="row{cycle values="1,2"}
{/foreach}
and then use div.row1 {...} and div.row2 {...}

hope this helps

Re: Different css class on every other news item?

Posted: Fri Aug 11, 2006 7:13 am
by RazorMedia
bloody excellent!
that did it - thanks

Re: Different css class on every other news item?

Posted: Fri Aug 18, 2006 4:43 pm
by ostricized
Hi all - I would like to do the same thing, and was able to partially recreate the effect based on this thread, but I do not understand enough to complete the task.

Pardon my ignorance - programming is not my strong suit.

I am using CMSMS v.13 Canary with News Module 2.013

In my summary template I wanted to alternate classes as well so I tried;



Which output the following;

Fatal error: Smarty error: [in module_db_tpl:News;displaysummary line 4]: syntax error: invalid attribute name: '...' (Smarty_Compiler.class.php, line 1533) in /path/to/public_html/lib/smarty/Smarty.class.php on line 1095

so I tried random bits of syntax like the following;



which outputs;



No error = Step in the right direction. However I truly do NOT know what the proper syntax that should complete the {foreach ...} loop is - If someone could provide further insight on this topic I would very much appreciate it.

Thank you for your time.

Re: Different css class on every other news item?

Posted: Fri Aug 18, 2006 4:50 pm
by tsw
As I didnt really look at the template code last time I just quessed it uses foreach loop :)

this is from svn version, but I quess it hasnt changed lately ;)

change

Code: Select all

{foreach from=$items item=entry}
<div class="NewsSummary">

{if $entry->formatpostdate}
to

Code: Select all

{foreach from=$items item=entry}
<div class="NewsSummary{cycle values="1,2"}">

{if $entry->formatpostdate}
at the beginning of the template

hope this helps

Re: Different css class on every other news item?

Posted: Fri Aug 18, 2006 5:40 pm
by ostricized
tsw: Thank you that was the solution.

Where I thought I needed;

Code: Select all

{foreach from=$items item=entry}
<div {foreach ...}class="news{cycle values="1,2"}{/foreach}">
...
{/foreach}
I only needed;

Code: Select all

{foreach from=$items item=entry}
<div class="news{cycle values="1,2"}">
...
{/foreach}

Hopefully this'll help others. Thanks again!