How would I style the news summary template to display block

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"
Post Reply
djkirstyjay
Forum Members
Forum Members
Posts: 206
Joined: Tue Oct 25, 2005 4:50 pm

How would I style the news summary template to display block

Post by djkirstyjay »

My title isn't explaining exactly what I want to do... but basically it's this...

I want the blocks of news to display in rows as follows - 3 items on the first row, 2 items on the second row and 1 item on each row after that.

This is so that I can style my homepage to display the news items in blocks in a sort of magazine-style front page. I will limit news items on the page to about 6 or 8 and have another dedicated news page that will display things in full.

So, I have to news code :

Code: Select all

<!-- Start News Display Template -->
{foreach from=$items item=entry}
<div class="NewsSummary">

{if $entry->postdate}
  <div class="NewsSummaryPostdate">
		{$entry->postdate|cms_date_format}
	</div>
{/if}

<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>

<div class="NewsSummaryCategory">
	{$category_label} {$entry->category}
</div>

{if $entry->author}
	<div class="NewsSummaryAuthor">
		{$author_label} {$entry->author}
	</div>
{/if}

{if $entry->summary}
	<div class="NewsSummarySummary">
		{eval var=$entry->summary}
	</div>

	<div class="NewsSummaryMorelink">
		[{$entry->morelink}]
	</div>

{else if $entry->content}

	<div class="NewsSummaryContent">
		{eval var=$entry->content}
	</div>
{/if}

{if isset($entry->extra)}
    <div class="NewsSummaryExtra">
        {eval var=$entry->extra}
	{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
    </div>
{/if}
{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="NewsSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->value}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->value}
        {/if}
     </div>
  {/foreach}
{/if}

</div>
<p>{/foreach}
  <!-- End News Display Template -->
But how would I write it using smarty to count the news then print 3 articles on the first line, 2 on the 2nd and 1 on all the rest? What would I count? item, or entry?

It's all very confusing...
atdesign
Forum Members
Forum Members
Posts: 38
Joined: Fri Feb 24, 2012 12:57 pm

Re: How would I style the news summary template to display b

Post by atdesign »

There may be a better solution but you could make categories for each layout type and use multiple news tags on the summary page.

E.g.:

<div class="firstrowcss">{News category="firstrow"}</div>
<div class="secondrowcss">{News category="secondrow"}</div>
<div class="thirdrowcss">{News category="thirdrow"}</div>
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: How would I style the news summary template to display b

Post by calguy1000 »

Actually, it isn't that tough... you just need a bit o smarty magic.

Something like this:

Code: Select all

{foreach from=$items item=entry name='foo'}
{if $smarty.foreach.foo.index < 3}
   {assign var='class' value='width33'}
{elseif $smarty.foreach.foo.index < 5}
   {assign var='class' value='width50'}
{elseif $smarty.foreach.foo.index < 6}
   {assign var='class' value='width100'}
{/if}
<div class="{$class}">
   // display your news stuff here.
</div>
{/foreach}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
djkirstyjay
Forum Members
Forum Members
Posts: 206
Joined: Tue Oct 25, 2005 4:50 pm

Re: How would I style the news summary template to display b

Post by djkirstyjay »

Wow calguy. That's exactly what I meant. Thanks!... and I understand what the code is doing perfectly, written out like that. :)

I shall give it a go.
Post Reply

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