How to Add the Tagging Function to CMS Made Simple Modules Part 2

In Part 1 we have learned how to assign multiple keywords (tags) to entries of CGBlog Module. Now I want to show you how to retrieve these tags in order to make them visible and clickable in the frontend and browse our entries by them.

We need a new “Summary Template” in CGBlog Module. Call it as you want like “Tag-Summary” and insert the following code (major code is just copied from sample):

<!-- Start CGBlog Display Template -->
{if isset($error)}{cgerror}{$error}{/cgerror}{/if}
{if $pagecount > 1}
{if $pagenumber > 1}
{$firstpage}&nbsp;{$prevpage}&nbsp;
{/if}
{$pagetext}&nbsp;{$pagenumber}&nbsp;{$oftext}&nbsp;{$pagecount}
{if $pagenumber < $pagecount}
&nbsp;{$nextpage}&nbsp;{$lastpage}
{/if}
</p>
{/if}
{foreach from=$items item=entry}
{if !empty($smarty.get.tag) && ($entry->fieldsbyname.Tags->value|strpos:"`$smarty.get.tag`" !== false)}
<div class="summary">
{if $entry->postdate}	<div class="date">{$entry->postdate|cms_date_format}</div>{/if}
<div class="title"><a href="{$entry->detail_url}">{$entry->title|escape}</a></div>

{if $entry->categories}
<div class="category">
{strip}{$category_label}
	{foreach from=$entry->categories item='category'}
		{$category.name}&nbsp;
	{/foreach}
{/strip}
</div>
{/if}

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

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

{if isset($entry->extra)}
	<div class="CGBlogSummaryExtra">
	{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="CGBlogSummaryField">
	{if $field->type == 'file'}
		<img src="{$entry->file_location}/{$field->value}"/>
	{elseif $field->name == 'Tags'}
			<h5>Tags</h5>
			{assign var="taglist" value=$entry->fieldsbyname.Tags->value}
			{assign var="tagwords" value=", "|explode:$taglist}
				{foreach from=$tagwords item=tagword}
					{assign var="tagword" value=$tagword|replace:",":""}
					{cms_selflink page=$page_alias urlparam="&amp;tag=`$tagword`" text=$tagword|trim}&nbsp;
				{/foreach}
	{else}
	{$field->name}:&nbsp;{eval var=$field->value}
	{/if}
	</div>
	{/foreach}
{/if}
</div>
{elseif empty($smarty.get.tag)}
<div class="summary">
{if $entry->postdate}	<div class="date">{$entry->postdate|cms_date_format}</div>{/if}
<div class="title"><a href="{$entry->detail_url}">{$entry->title|escape}</a></div>

{if $entry->categories}
<div class="category">
{strip}{$category_label}
	{foreach from=$entry->categories item='category'}
		{$category.name}&nbsp;
	{/foreach}
{/strip}
</div>
{/if}

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

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

{if isset($entry->extra)}
	<div class="CGBlogSummaryExtra">
	{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="CGBlogSummaryField">
	{if $field->type == 'file'}
		<img src="{$entry->file_location}/{$field->value}"/>
	{else}
	{$field->name}:&nbsp;{eval var=$field->value}
	{/if}
	</div>
	{/foreach}
{/if}
</div>

{/if}
{/foreach}
<!-- End CGBlog Display Template -->

Save it and make it the default “Summary Template”. Now take a look in the frontend and you will see, you can click the keywords.
FINISHED
Run the CGBlog module by inserting {CGBlog} into your desired page. Make sure your posts are published and contain keywords (tags).

Additional Notes: Just to understand the above code, you can read further. Here I just have added two important codesnippets.

{if !empty($smarty.get.tag) && ($entry->fieldsbyname.Tags->value|strpos:"`$smarty.get.tag`" !== false)}

Here we look if the get paramater is set and not empty and if some of our entries contain the keyword.
IF TRUE, we show the template code with our keywords:

{if isset($entry->fields)}
	{foreach from=$entry->fields item='field'}
	<div class="CGBlogSummaryField">
	{if $field->type == 'file'}
		<img src="{$entry->file_location}/{$field->value}"/>
	{elseif $field->name == 'Tags'}
			<h5>Tags</h5>
			{assign var="taglist" value=$entry->fieldsbyname.Tags->value}
			{assign var="tagwords" value=", "|explode:$taglist}
				{foreach from=$tagwords item=tagword}
					{assign var="tagword" value=$tagword|replace:",":""}
					{cms_selflink page=$page_alias urlparam="&amp;tag=`$tagword`" text=$tagword|trim}&nbsp;
				{/foreach}
	{else}
	{$field->name}:&nbsp;{eval var=$field->value}
	{/if}
	</div>
	{/foreach}
{/if}

IF FALSE (elseif empty…) we show the regular code = all entries.
This example works well with CGBlog but you can actually apply it to any other module. I just wanted to show you a possible way to achieve this function.

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

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

Author Spotlight

Nic Bug

Nic Bug

I am a freelance web designer from Germany and CMS Made Simple is my every day tool. I have been using it since 2007 and I love it because it’s so easy to use. Even my clients understand and use it daily. I also have my own CMS Made Simple project called www.TemplateMadeSimple.com. There, you will find premium templates for made for CMS Made Simple.

7 Comments on How to Add the Tagging Function to CMS Made Simple Modules Part 2

  1. Emilio says:

    I’ve tried this with CMSMS 1.11.1 and CGBlog 1.9.8 and no luck :(

  2. Emilio says:

    Which versions of CMSMS and CGBlog did you test it with?

  3. Emilio says:

    I tried it on 1.10.3 and yes it works! Great job Nic Bug. What needs to be done to make it work on 1.11.1? We’ve been working hard on a web build on 1.11.1 and this would be the icing on the cake.

  4. cath says:

    I have tried this on 1.11 the backend works great, but I can only see plain text field on front end? Any ideas what I need to change to make clickable – thanks

    • Nic Bug Nic Bug says:

      thats way to unspecific. i’m afraid i can’t help you. i need more details. which text field? what contains the text field? is there a template wrapped around the textfield?

Leave a Reply

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


9 + = 13

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>