Entering Tags at CGBlog articles

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1872
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Entering Tags at CGBlog articles

Post by Gregor »

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

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}&nbsp &nbsp;
                           {/foreach}
                      {/if}
                  {else}
                      {$field->name}: {eval var=$field->value}
                  {/if} 
            </div>
      {/foreach}
{/if}
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:

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}:&nbsp;{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}:&nbsp;{eval var=$field->value}
               {/if}
               </div>
            {/foreach}
        {/if}
    {/if}
{/foreach}
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
Last edited by Gregor on Mon May 07, 2012 3:01 pm, edited 1 time in total.
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

thank you. do you have an idea for tag suggestion in backend?
it would be nice if you start typing a tag and cmsms makes suggestions for tags which already exists.
User avatar
Gregor
Power Poster
Power Poster
Posts: 1872
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Entering Tags at CGBlog articles

Post by Gregor »

That indeed would awsome. I don't have an clue how that can be done. any volunteers?

Gregor
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

actually its not that difficult if we use this script: http://webspirited.com/tagit/

it provides a very neat suggestion of tags. all we need to do, is to fill the given array with all tags of all entries, which are saved in our custom field.
i will take a look into it.
quick preview: http://adrop.in/pMg
User avatar
Gregor
Power Poster
Power Poster
Posts: 1872
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Entering Tags at CGBlog articles

Post by Gregor »

Sounds like a very nice solution. Was not aware of something like that.
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

i was playing around with it and finally i am pretty satisfied with the result: http://www.youtube.com/watch?v=OGl1rBHFFY8

i think, i will write a complete tutorial on how to get this. it will work pretty good with your code Gregor
User avatar
Gregor
Power Poster
Power Poster
Posts: 1872
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Entering Tags at CGBlog articles

Post by Gregor »

That really looks nice! Does it store the tags as comma separated values? In the code for sending out a tweet as soon as an article is posted, the tags are used along with the tweet --> #tag1 #tag2 etc.

Grtz., Gregor
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

Database looks like this…
dbview.png
therefore its very easy to use the script in other modules too!
User avatar
Gregor
Power Poster
Power Poster
Posts: 1872
Joined: Thu Mar 23, 2006 9:25 am
Location: The Netherlands

Re: Entering Tags at CGBlog articles

Post by Gregor »

Well, in that case, I'm willing to give it a try ;) Nice job you've done so far!

Grtz., Gregor
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

to all: if you also need tagging function, read my detailed article at arvixe about tagging in cms made simple
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Entering Tags at CGBlog articles

Post by carasmo »

I dig this a lot! Thanks!
otelo
Forum Members
Forum Members
Posts: 28
Joined: Wed Oct 01, 2008 9:05 pm

Re: Entering Tags at CGBlog articles

Post by otelo »

I tried it on 1.10.3 and yes it works! Great job nicmare.
However on 1.11.1 it doesn't work for some reason that I can't figure out. What needs to be done to make it work on 1.11.1? Does anybody have the answer?
We’ve been working hard on a web build on 1.11.1 and this would be the icing on the cake.
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

i am not sure. try to implement this into 1.11.1 and tell me what errors you get.
otelo
Forum Members
Forum Members
Posts: 28
Joined: Wed Oct 01, 2008 9:05 pm

Re: Entering Tags at CGBlog articles

Post by otelo »

nicmare wrote:i am not sure. try to implement this into 1.11.1 and tell me what errors you get.
I've followed the steps you describe in your tutorial http://blog.arvixe.com/add-tagging-func ... les-part1/ but when I go to 'Add blog entry' in Content > Calguys Blog Module I get a blank screen. I check the source code and only get this line

Code: Select all

<div class="pagecontainer"><div class="pageoverflow"></div>
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am
Location: Berlin

Re: Entering Tags at CGBlog articles

Post by nicmare »

activate debug mode in config.php (check doc file)
and watch admin log for any errors. they should lead us to the right direction
Locked

Return to “Tips and Tricks”