Using News "Fields," Make Summary Link Directly to Content Page

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
Walkere
Forum Members
Forum Members
Posts: 12
Joined: Sat Oct 13, 2007 11:21 pm

Using News "Fields," Make Summary Link Directly to Content Page

Post by Walkere »

As I was adding content to my site, I faced a bit of a conundrum - I like using the News module to highlight new content pages, but I never have anything to put into the "Content" section of the News.  It seemed, for my needs, to be more efficient to have the News title link directly to content page that it was advertising.

Using the new "Fields" feature of the News module and a little editing of the template, I got this working.

First, in the "News" module you need to go to "Field Definitions" and create a new field - I called mine cms_selflink.  The field holds the Page No. of the page that we're advertising with the News entry.  (Note: If you have an older version of news, you can use the "Extra" field)

Now, in the News template, we can use $entry->cms_selflink to get the Page No. that we entered.

$entry->titlelink is the standard link produced by the Summary template.  We can replace that with a {cms_selflink} tag.  The title of the post comes stored in $entry->title, so between that and $entry->cms_selflink we have all the info we need.  The tag would simply be {cms_selflink page=$entry->cms_selflink text=$entry->title}.

I also threw an {if} statement in to check that the cms_selflink field is filled - if not, we can assume it's a regular News entry (with no associated content page) and use the standard $entry->titlelink.

Here's a full copy of the Summary Template, as I'm currently using it...

Code: Select all

<!-- Start News Display Template -->

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

{if $entry->formatpostdate}
	<div class="NewsSummaryPostdate">
		{$entry->formatpostdate}
	</div>
{/if}

<div class="NewsSummaryLink">
   {if isset($entry->cms_selflink)}
      {cms_selflink page=$entry->cms_selflink text=$entry->title}
   {else}
      {$entry->titlelink}
   {/if}
</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">
	   {if $pagecount > 1}
              <p>
              {if $pagenumber > 1}
              {$firstpage} {$prevpage} 
              {/if}
              {$pagetext} {$pagenumber} {$oftext} {$pagecount}
              {if $pagenumber < $pagecount}
               {$nextpage} {$lastpage}
             {/if}
             </p>
             {/if}
	</div>

{else if $entry->content}

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

</div>
{/foreach}
<!-- End News Display Template -->
You can see it in action on the front page of my site - off in the right column, underneath the first ad block.

- Walkere
Image
Locked

Return to “Tips and Tricks”