News Module Tips and Tricks for CMS Made Simple

CMS Made Simple Basics – News Module Enhancements

This article will show some tips and tricks to make your CMS Made Simple News module shine. The News module is included as part of the core CMS Made Simple package. It features search engine friendly URLs, categories, custom fields, draft management, scheduled postings, and article expiration. It has full template support allowing for multiple summary and full article templates. Articles can also be managed from the frontend of your website if you are using the Frontend Users Management module. One of the recently added features is the ability to assign a custom URL that breaks away from the traditional URL structure which includes the article’s ID number and the article’s landing page ID number.

CMS Made Simple

The News module can be used as a blogging tool, event list, announcements, and anything else that requires dated entries. For a more robust blogging tool, try the CGBlog module available from the CMS Made Simple Development Forge. Note: the tutorials shown in this article can apply to the News, CGBlog, and other similar modules.

~Sticky Articles~
The following will show how to make articles “Sticky”, or in other words, assign one or more articles to be pinned to the top of all other articles regardless of their post dates. This is helpful if there is a special announcement or news that you want listed first even as additional posts are published.

Create a new Field Definition
Open the News module in the Admin Console and go to the Field Definitions tab. Click the, “Add Field Definition” link and create a new “Checkbox” called, “Sticky”. Next, check the “Public” option and press Submit to save the new field. The Public option is needed so it can be used in the template’s code.

Create a new Summary Template
Next, create a new Summary Template called, “Sticky”. It will have the default template code pre-loaded which can be used during this tutorial. However, I’ll use a slightly more minimal template in the examples. The template will not include the author, category, the extra field, or article pagination.
To separate, or rather, distinguish between articles assigned as Sticky and those that are not, the template will use two foreach loops. Both loops will check the value of the field, called “Sticky”. If the article editor checks the Sticky option, the template will use the first foreach loop to show it on top of the regular articles.

Create the Loops
Find the foreach loop that looks like: {foreach from=$items item=entry}
Copy everything in the foreach loop including that first statement and the closing {/foreach} tag. Then paste the contents below the closing {/foreach} tag to create the second foreach loop. Below is an example using a slightly minimal version of the default Summary 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>

{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->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="NewsSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->displayvalue}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->displayvalue}
        {/if}
     </div>
  {/foreach}
{/if}

</div>
{/foreach}

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

{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->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="NewsSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->displayvalue}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->displayvalue}
        {/if}
     </div>
  {/foreach}
{/if}

</div>
{/foreach}

Assign the Sticky Field Value
Now we need to find out if an article has been assigned as Sticky and assign the value to a Smarty variable. Do this immediately below the first foreach loop from the previous step ({foreach from=$items item=entry}):

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
          {if $field->name == 'Sticky'}{assign var='Sticky' value=$field->displayvalue scope='global'}{/if}
  {/foreach}
{/if}

Now each $items loop will have a variable called, $Sticky, which will hold the value of the Sticky field. Use an {if}{/if} statement in the foreach loop to determine if the article has been set as Sticky. Selected checkbox field definitions have a value of “1” while un-checked boxes have a value of “0”.

Test if an Article is Sticky
Immediately before the opening div place the following: {if $Sticky == ‘1’}.

{if $Sticky == '1'}
<div class="NewsSummary">

Find the closing div and place the closing {/if} tag immediately after it.

Go to the second $items foreach loop and repeat the steps above to include the $entry->fields loop and create the {$Sticky} variable. Remember, the second foreach loop will show articles that are not Sticky. Therefore, we are checking if the variable has a value of “0” which means the Sticky field was not selected.

{if $Sticky == '0'}
<div class="NewsSummary">

Be sure to include the closing {/if} immediately before the closing {/foreach} tag of the second loop.

Hide the Sticky field from the Article Summary
The template shown in the example above includes the foreach statement that loops through all of the custom Field Definitions. Therefore, the Sticky field needs to be filtered out of the template or there will be a 1 or 0 shown for each article. This is easily done by using an if statement to filter out the Sticky field name: {if $field->name != ‘Sticky’}

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
	{if $field->name != 'Sticky'}
     <div class="NewsSummaryField">
        {if $field->type == 'file'}
          <img src="{$entry->file_location}/{$field->displayvalue}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->displayvalue}
        {/if}
     </div>
	{/if}
  {/foreach}
{/if}

Be sure to do this for both of the foreach loops.

~Search Engine Friendly Detail Article Page Titles~
When an article summary’s “Read More” link is followed, the full article shows on a new page. If that page’s Title is called, “News”, for example, we can replace “News” with the article’s title creating better SEO. This is especially true if your page title is contained in a header 1 (<h1>) element.

Assign the Article’s Title to a Smarty Variable
Open your News Detail Template and place the following snippet as the first line:

{assign var='ArticleTitle' value=$entry->title|cms_escape:htmlall scope='global'}

This assigns the article’s title to a Smarty template variable that can be used in a Layout Template. Save the template changes.

Include the Article Title in the Layout Template
Next, open the template assigned to the page being used to display the full article view. Test if the article’s title is set using the {$ArticleTitle} variable. If it is set, then use it as the page title. If it is not set, then the default title is used instead.

At the very top of Layout Template, enter the following:

{if isset($ArticleTitle)}{capture assign='Title'}{$ArticleTitle}{/capture}{else}{capture assign='Title'}{title}{/capture}{/if}

Next, find the {title} tag inside of the template <body> and replace it with {$Title}. Now, when an article is viewed, the page’s title will use the article’s title helping to add SEO value to the page.

~Search Engine Friendly Meta Tags~
To further increase the SEO value of an article, the page’s <title></title> element can also use the Article title. The location of thetag will vary depending upon how your CMSMS site was set up. The default location is inside of the Layout Template. But, some developers place it in the metadata field under the Page Options settings, or inside of the Global Metadata. Regardless where the title tag is located, do the following to use the {$ArticleTitle} value when it is available:

<title>{if isset($articleTitle)}{$articleTitle}{else}{title}{/if} | {sitename}</title>

This will generate something like this and should be indexed nicely by search engines:

<title>Search Engine Friendly Meta Tags | Arvixe Blog</title>

Do you have a favorite technique to enhance the News module? Post comments, suggestions, and questions below.


Looking for quality CMS Made Simple Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , | Posted under CMS Made Simple | RSS 2.0

Author Spotlight

JohnnyB

JohnnyB

I've been a full-time front-end web developer for nine years working with design and marketing agencies and businesses located all over the USA. CMS Made Simple has been my go-to Content Management System since mid 2006.

2 Comments on News Module Tips and Tricks for CMS Made Simple

  1. Fa says:

    Would you give us the trick how to search News Article filtering by News Category and keyword? Your help is much appreciated.

    • kensley says:

      No tricks needed. Simply create a drop down list from the news field definitions. Store category names to that list. Then associate each article to a category name from that list. Done.

Leave a Reply

Your email address will not be published. Required fields are marked *


2 − = 0

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>