Entering Tags at CGBlog articles
Posted: Tue Mar 27, 2012 5:18 am
Not another metatag T&T, but a way to enter tags (keywords) to your cgblog and do a selection on related articles. I'll describe the steps to make it work.
But first I'd like to thank Rolf for sort of 'pushing' me to start developing this and Uniqu3 who helped me extensively and came up with a working solution. Great help guys!
1. Create a page, f.i. CGBlog (or use your regular cgblog page). Enter the same name in te alias field (Optiones -> Alias)
2. Enter at least {CGBlog}, add the option as described in the help CGBlog, however for this example it is not required.
3. Create a page and name it cgblog_logboek. Enter the same name in te alias field (Optiones -> Alias)
4. Create an Extra field (CGBlog -> Field Definition) in CGBlog and name it Tags, value tex input, 50 char long. The length is your choice as long as you create enough space to enter tags.
5 . Enter in the content field {CGBlog summarytemplate="MyTagTemplate"}
6. Create a CGBlog detail template and name it Tag_detail. Could be any name as log as it is either your default template. In case it is not your default template, enter detailtemplate="<what ever name you use>" to the tag created at 2.
7. Inside he detail template you just created, go to the part where the extra fields are checked '{if isset($entry->fields)}' Replace that part untill the closing {/if} withe following code
8. Create a CGBlog Summary template and name MyTagTemplate, or at least the same name used at 5. Replace the standard enterted code by the following code. You might noticed the lay-out of the template is put in twice. See comments inside the code. If you have/want antoher lay-out, make sure you duplicate that code at the places shown:
9. If you go your CGBlog articles (or create new articles), you will find an extra field called Tags. Here you enter your comma separated tags, f.i.
cmsms, cgblog, whatever you like
10. By viewing your clog article, you'll see the tags you entered. Click on and you will see the articles that have the same tag. A working example can be found here http://test.uisge-beatha.eu/index.php?page=cgblog
Enjoy!
Gregor
But first I'd like to thank Rolf for sort of 'pushing' me to start developing this and Uniqu3 who helped me extensively and came up with a working solution. Great help guys!
1. Create a page, f.i. CGBlog (or use your regular cgblog page). Enter the same name in te alias field (Optiones -> Alias)
2. Enter at least {CGBlog}, add the option as described in the help CGBlog, however for this example it is not required.
3. Create a page and name it cgblog_logboek. Enter the same name in te alias field (Optiones -> Alias)
4. Create an Extra field (CGBlog -> Field Definition) in CGBlog and name it Tags, value tex input, 50 char long. The length is your choice as long as you create enough space to enter tags.
5 . Enter in the content field {CGBlog summarytemplate="MyTagTemplate"}
6. Create a CGBlog detail template and name it Tag_detail. Could be any name as log as it is either your default template. In case it is not your default template, enter detailtemplate="<what ever name you use>" to the tag created at 2.
7. Inside he detail template you just created, go to the part where the extra fields are checked '{if isset($entry->fields)}' Replace that part untill the closing {/if} withe following code
Code: Select all
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="CGBlogDetailField">
{if $field->type == 'image'}
<img class="hidden" src="{$entry->file_location}/thumb_{$field->value}" alt="" />
{elseif $field->name == 'Tags'}
{if $field->name != ""} {* tags to show *}
<h5>Tags</h5>
{assign var="taglist" value=$entry->fieldsbyname.Tags->value}
{assign var="tagwords" value=", "|explode:$taglist}
{foreach from=$tagwords item=tagword}
{cms_selflink page="cgblog_logboek" urlparam="&tag=`$tagword`" text=$tagword|trim} 
{/foreach}
{/if}
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
Code: Select all
<!-- Start CGBlog Display Tag Template -->
{if isset($error)}{cgerror}{$error}{/cgerror}{/if}
{foreach from=$items item=entry}
{*check url for param tag= and compare to extra field *}
{if !empty($smarty.get.tag) && ($entry->fieldsbyname.tags->value|strpos:"`$smarty.get.tag`" !== false)}
{* ... here do whole summary template as you want to have it ... *}
{if $entry->postdate}
<div class="CGBlogSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="CGBlogSummaryLink">
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a>
</div>
{if $entry->summary}
<div class="CGBlogSummarySummary">
{eval var=$entry->summary}
</div>
{else if $entry->content}
<div class="CGBlogSummaryContent">
{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}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
{elseif empty($smarty.get.tag)}
{* ... repeat the template so it'S not empty if someone comes to page without using urlparam ... *}
{if $entry->postdate}
<div class="CGBlogSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="CGBlogSummaryLink">
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a>
</div>
{if $entry->summary}
<div class="CGBlogSummarySummary">
{eval var=$entry->summary}
</div>
{else if $entry->content}
<div class="CGBlogSummaryContent">
{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}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
{/if}
{/foreach}
cmsms, cgblog, whatever you like
10. By viewing your clog article, you'll see the tags you entered. Click on and you will see the articles that have the same tag. A working example can be found here http://test.uisge-beatha.eu/index.php?page=cgblog
Enjoy!
Gregor