Different css class on every other news item?

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Locked
RazorMedia

Different css class on every other news item?

Post 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/
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Different css class on every other news item?

Post 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
RazorMedia

Re: Different css class on every other news item?

Post by RazorMedia »

bloody excellent!
that did it - thanks
ostricized

Re: Different css class on every other news item?

Post 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.
tsw
Power Poster
Power Poster
Posts: 1408
Joined: Tue Dec 13, 2005 10:50 pm

Re: Different css class on every other news item?

Post 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
ostricized

Re: Different css class on every other news item?

Post 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!
Locked

Return to “Layout and Design (CSS & HTML)”