tags?

19 posts by 4 authors in: Forums > CMS Builder
Last Post: June 1, 2009   (RSS)

By Toledoh - May 17, 2009

Hi All,

Not sure if I'm using the right terminology, but I'm trying to add a filtering process to a bunch of articles - and I'm wondering if my methodology is right... or could be better :)

I'm thinking of creating a table of "tags" such as "news", "events", "video", "Product type 1" "Product type 2" etc etc. Each article can have 1, 2 or 20 "tags" relative to it's content.

Then, when I display the articles on the site, we can "view all" or just view articles with the appropriate tags.

I can then also show an article, and have a "related articles" link etc.

The list viewer mock-up is here:
http://www.portstephenswinery.com/murrays2009/posts.php

Cheers,
Tim
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] tags?

By ross - May 18, 2009

Hi Tim

Thanks for posting!

I see what you mean there :). I can walk you through setting something like that up. It's a little tricky though. If you want, we can just setup a consulting project for you.

Basically though, you'll have a field called tags. When you create a new record, you enter the tags in a comma separated list.

On the display page, you need to pull the value of that field use some PHP to turn each one into a link and then have those links run keyword searches on that field.

Does that sound like something you wanted to give a shot if I explain it all?

Let me know :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] tags?

By Toledoh - May 18, 2009

That sounds perfect Ross.

I'd like to do it myself so I gain the understanding if that's OK with you?

With the coma separated... the mock up above uses a table, which I then use to produce the classes - which I need without comas... ie <li class="tag1 tag2">. Tags with multipe words need to be hyphenated, ie. tag-number-1. Will this be an issue?

Cheers,
Tim
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] tags?

By ross - May 19, 2009

Hi Tim

I don't that will be a problem becasue we are going to be using a separate field for the time being. It almost seems like you might be able to use the same one for both but this time, let's just create a new field.

It will be called "Tags" and will be setup as a text field.

Once you create that field, add some values to it for each record. For example: keyword1, keyword2, keyword3, etc

From there, go to your display page and make that field appear just below the image for each record. It won't really be formatted nicely just yet, but don't worry about that.

Get all that going for now and let me know how you make out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] tags?

By Toledoh - May 19, 2009 - edited: May 19, 2009

OK Ross,

I've set up a new page at http://www.portstephenswinery.com/murrays2009/test.php

I'll play with formatting a bit as well go.

[edit: I've got the posts.php working again now - with the tags]

Cheers,
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] tags?

By ross - May 21, 2009

Hi Tim

That's great!

The next step will be adding some code to your pages to turn those tags into links. What you'll be doing is turning the tags field into an array (based on the comma) and then displaying each item of that array. The code looks like this:

<?php $tags = explode(",", $record['tags']); ?>

<?php foreach ($tags as $tag): ?>
<?php $trim_tag = trim($tag); ?>
<a href="page.php?tags_keyword=<?php echo $trim_tag; ?>"><?php echo $trim_tag; ?></a>,
<?php endforeach ?>


Just make sure on the first line there that you use the proper field name for $record['tags']. Also make sure the link goes where you need it.

Give that a shot and let me know you what you think :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] tags?

By Toledoh - May 21, 2009

Working a treat so far Ross!

http://www.portstephenswinery.com/murrays2009/posts.php

I've placed the code in twice, once to display the tags as links, and again within the <li class="###"> which I need for my filtering jQuery. This leaves the comma and the link out as they're not required.

For some reason however, the link in the display area is inserting a line break, so the tags are displayed;

tag1
,
tag2
,
tag3....

where they should be displayed tag1, tag2, tag 3...


Any ideas?

Thanks!
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] tags?

By ross - May 22, 2009

Hi Tim

Thanks for the update. Glad to hear that all worked out :).

For displaying all the tags, I think what you could do is setup a loop that appends all the tag values to an array so in the end, you have an array with every single tag in it. There is PHP function that will pull out all the unique values from one array and stick them into a second array.

I think that's the way to go. Let me know what you think :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] tags?

By Toledoh - May 24, 2009

Hi Ross,

All going well - thanks a lot.

Yes, I think we're heading in the right direction - however if we simply just loop the tags, will we not get duplicates? That is why I initially placed the tags in a separate table.

I'm trying to end up with something like the "Top Tags" in the right column here http://allrecipes.com.au/recipe/8285/sausage-rolls.aspx

Would be great also if there was a way of identifying the number of times the tags have been used... then in the displaying of them, we could just show the top 10 tags or something like that...

What do you think?

Cheers,
Cheers,

Tim (toledoh.com.au)