How to separate News articles in output? Topic is solved

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
jakovbak
Forum Members
Forum Members
Posts: 225
Joined: Thu Dec 13, 2012 2:54 pm

How to separate News articles in output?

Post by jakovbak »

Hello folks!
Is there a way to separate News articles in output? This is how it looks by default:

Code: Select all

<div class="newsarticles">
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
</div>
"newsimage" and "NewsSummary" come in pairs and they both belong to one News article. What I'm trying to achieve is this:

Code: Select all

<div class="newsarticles">
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
</div>
<div class="newsarticles">
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
</div>
In short, how could one make each article to be wrapped in separate <div> in output?

This is my NewsSummary template:

Code: Select all

<!-- Start News Display Template -->
<div class="newsarticles">

{foreach from=$items item=entry}

{* NEWS SUMMARY IMAGE - class="bi-pic" *}
	{if isset($entry->fields)}
		{foreach from=$entry->fields item='field'}
			<div class="bi-pic">
				{if $field->type == 'file'}
					{if isset($field->value) && $field->value}
						<img src="{$entry->file_location}/{$field->value}"/>
					{/if}
				{/if}
			</div>
		{/foreach}
	{/if}
{* NEWS SUMMARY IMAGE - class="bi-pic" - END FIELD *}

{* NEWS SUMMARY TEXT - class="bi-text" *}
	<div class="NewsSummary">
		<div class="bi-text">
			{* NEWS SUMMARY LINK/TITLE - class="bi-text" *}
			<h5><a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a></h5>
			{* NEWS SUMMARY AUTHIR/DATE/CATEGORY - class="bi-text" *}
			<ul>
				<li>{$author_label} {$entry->author}</li>
				<li>{$entry->postdate|cms_date_format}</li>
				<li>{$category_label} {$entry->category}</li>
			</ul>
			{if $entry->summary}
				<p>{$entry->summary}</p>
			{else if $entry->content}
				{$entry->content}
			{/if}
		</div>
	</div>
{* NEWS SUMMARY TEXT - class="bi-text" - END FIELD*}

	{if isset($entry->extra)}
		<div class="NewsSummaryExtra">
			{$entry->extra}
			{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
		</div>
	{/if}
{/foreach}

</div>
<!-- End News Display Template -->
Thank you in advance for any idea or direction you may come up with!
Bes regards,
jakovbak
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1610
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: How to separate News articles in output?

Post by DIGI3 »

The {foreach}...{/freach} iterates through your news articles, so anything you want to appear for each article should be inside them. My guess is that you want to move the <div class="newsarticles"> and corresponding closing div inside the foreach loop.
Not getting the answer you need? CMSMS support options
johnboyuk1
Forum Members
Forum Members
Posts: 192
Joined: Mon Nov 26, 2018 3:09 pm

Re: How to separate News articles in output?

Post by johnboyuk1 »

agreed.. like this:

Code: Select all


<!-- Start News Display Template -->


{foreach from=$items item=entry}
<div class="newsarticles">
{* NEWS SUMMARY IMAGE - class="bi-pic" *}
	{if isset($entry->fields)}
		{foreach from=$entry->fields item='field'}
			<div class="bi-pic">
				{if $field->type == 'file'}
					{if isset($field->value) && $field->value}
						<img src="{$entry->file_location}/{$field->value}"/>
					{/if}
				{/if}
			</div>
		{/foreach}
	{/if}
{* NEWS SUMMARY IMAGE - class="bi-pic" - END FIELD *}

{* NEWS SUMMARY TEXT - class="bi-text" *}
	<div class="NewsSummary">
		<div class="bi-text">
			{* NEWS SUMMARY LINK/TITLE - class="bi-text" *}
			<h5><a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a></h5>
			{* NEWS SUMMARY AUTHIR/DATE/CATEGORY - class="bi-text" *}
			<ul>
				<li>{$author_label} {$entry->author}</li>
				<li>{$entry->postdate|cms_date_format}</li>
				<li>{$category_label} {$entry->category}</li>
			</ul>
			{if $entry->summary}
				<p>{$entry->summary}</p>
			{else if $entry->content}
				{$entry->content}
			{/if}
		</div>
	</div>
{* NEWS SUMMARY TEXT - class="bi-text" - END FIELD*}

	{if isset($entry->extra)}
		<div class="NewsSummaryExtra">
			{$entry->extra}
			{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
		</div>
	{/if}
	</div>
{/foreach}


<!-- End News Display Template -->

jakovbak
Forum Members
Forum Members
Posts: 225
Joined: Thu Dec 13, 2012 2:54 pm

Re: How to separate News articles in output?

Post by jakovbak »

Yes! Thank you guys, this works like a charm and you saved my day!
Post Reply

Return to “CMSMS Core”