Only show last news article on page

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Only show last news article on page

Post by Keithb »

I'm hoping to only show the most recent news article on our homepage as a short snippet with xx amount of characters in the preview, but then allow them to view previous articles.  My other option to edit the homepage all the time, but I'd like to use the built in News module.

Is this possible?  I looked at the newsSummarypage template but was unable to determine what to change in order to get this to work.  Any ideas?
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Only show last news article on page

Post by jmcgin51 »

You need to read the News module help.  This is very possible and very easy.
owr_bgld

Re: Only show last news article on page

Post by owr_bgld »

In the Module help you can find the parameter "number":

Code: Select all

{news number="1"}
shows the last ONE news
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Re: Only show last news article on page

Post by Keithb »

owr_web wrote: In the Module help you can find the parameter "number":

Code: Select all

{news number="1"}
shows the last ONE news
Thank you.  I didn't think about using the 1.  The help didn't state which 1 would be used but I guess that is based on your criteria.

My goal is to get it to look like:
Our News

A Warning Shot from Mother  <--  That would be article link.
The news snippet would go here and you would put what you want to.  Just text Just test Just text Just test Just text Just test Just text Just test Just text Just test v v Just text Just test v v .. |READ MORE|  <---- would be right next to article.
Last edited by Keithb on Thu Aug 12, 2010 1:40 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Only show last news article on page

Post by Dr.CSS »

The News will always show the latest news on top or first as the case may be, so limiting it to 1 article will show the latest...

In the summary template what you show you want is some of the default template calls, so make a new one or edit the existing summary template to only have the title link div, the summary div, and the more link div, when calling the News tag use moretext='|READ MORE|' parameter...
User avatar
pixelita
Power Poster
Power Poster
Posts: 388
Joined: Sun Sep 16, 2007 3:07 am

Re: Only show last news article on page

Post by pixelita »

Here's an example. We have the last three news items, but you could narrow it to one.  Then it links to the detail page. You can also provide links for folks to browse by date or by category as we have here:
http://idylwood.org/

Here's the code to pull the box into the sidebar. (We use a global content block.)

Code: Select all

<div id="news">
<h2>News</h2>
<div id="news-container">
{news number='1' summarytemplate='News Summary' detailpage='news'}
</div><!-- /news-container -->
</div><!-- /news -->
Then your detail page looks like this:

Code: Select all

<!-- Idylwood News Detail Template -->
{if $entry->formatpostdate}
	<div id="NewsPostDetailDate">
		{$entry->formatpostdate}
	</div>
{/if}
<h3 id="NewsPostDetailTitle">{$entry->title}</h3>

<hr id="NewsPostDetailHorizRule" />

{if $entry->summary}
	<div id="NewsPostDetailSummary">
		<strong>
			{eval var=$entry->summary}
		</strong>
	</div>
{/if}

{if $entry->category}
	<div id="NewsPostDetailCategory">
		{$category_label} {$entry->category}
	</div>
{/if}

<div id="NewsPostDetailContent">
	{eval var=$entry->content}
</div>


<p><a href="/news/news-archives">View all news items</a>.<br />
<a href="/news/topics">View news items by category</a>.</p>

<!-- /Idylwood News Detail Template -->
And your summary page looks like this:

Code: Select all

<!-- Idylwood News Summary Template -->
<!-- This is what appears in the News Box on the sidebar -->
{if $pagecount > 1}
  <p>
{if $pagenumber > 1}
{$firstpage} {$prevpage} 
{/if}
{$pagetext} {$pagenumber} {$oftext} {$pagecount}
{if $pagenumber < $pagecount}
 {$nextpage} {$lastpage}
{/if}
</p>
{/if}
{foreach from=$items item=entry}
<div class="NewsSummary">
{if $entry->formatpostdate}
	<div class="NewsSummaryPostdate">
		{$entry->formatpostdate}
	</div>
{/if}

<div class="NewsSummaryLink">
	{$entry->titlelink}
</div>

{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}

</div>
{/foreach}
<!-- VIEW NEWS ARCHIVES -->
<p>View <a href="/news/news-archives">Date Archives</a><br />
View <a href="/news/topics">Category Archives</a></p>
<!-- FEEDBURNER LINK -->
	{global_content name='news-feed'}
<!-- /Idylwood News Summary Template -->
And of course you create pages for the date archives and category archives:
1. Create a parent page, "News."  Leave it blank (CMSMS won't let you do this so just put a space in the "content" box and save the page.
2. Create a subpage called "Date Archives" and insert this code in the content box:

Code: Select all

<h3>Browse News Archives</h3>
{news showarchive='0'}
3. Create a subpage called "Category Archives" and insert this code in the content box:

Code: Select all

<h3>Browse News Topics</h3>
{news browsecat='1' browsecattemplate='topics'}
4. And in the News module, create a category template:

Code: Select all

{if $count > 0}
<ul class="topics">
{foreach from=$cats item=node}
{if $node.depth > $node.prevdepth}
{repeat string="<ul>" times=$node.depth-$node.prevdepth}
{elseif $node.depth < $node.prevdepth}
{repeat string="</li></ul>" times=$node.prevdepth-$node.depth}
</li>
{elseif $node.index > 0}</li>
{/if}
<li class="newscategory">
{if $node.count > 0}
	<a href="{$node.url}">{$node.news_category_name}</a> ({$node.count}){else}<span>{$node.news_category_name} (0)</span>{/if}
{/foreach}
{repeat string="</li></ul>" times=$node.depth-1}</li>
</ul>
{/if}
<p><a href="http://feeds.feedburner.com/RssFeed-Idylwood" rel="alternate" type="application/rss+xml"><img src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/RssFeed-Idylwood" rel="alternate" type="application/rss+xml">Subscribe in a reader</a></p>
HTH. Contact me offlist if you want help with this.
Submit your site to the We Love CMSMS showcase
Post Reply

Return to “The Lounge”