Keyword

Tagging categories

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 2 months ago #85053 by Nick
Tagging categories was created by Nick
How tough would it be to code a piece of script to be able to tag categories?

 

The reason I want to do this is because I want to be able to put certain categories in certain genres (anime site). I thought what better way to do it than with tags. So i give each category a certain tag and then I'll be able to list all the tags on a page. Clicking a tag will show all the categories with that tag.

 

I'm somewhat of a noob to php and i am willing to try to make this work. Would this be hard to do? Never wrote anything significant in php before. Could I do this?

 

I would greatly appreciate it if someone is able to write this script or even implement it into K2 2.3

 

Here's my workflow:

 

Have a completely new table called k2_category_tag

have 2 columns where the tag is linked to the categories so left side is the tag and right side is the category id's seperated by comma.

 

List all the tags. Once a tag is clicked the script will get all the category id's listed for that tag.

 

Is this the right way to do this?

 

This should be the same worflow if someone wants to add a favorites system to K2.

Please Log in or Create an account to join the conversation.

More
14 years 3 weeks ago #85054 by Lloyd Sims
Replied by Lloyd Sims on topic Tagging categories
I've created a category tagging system of sorts on my test site. It works exactly like item tags... but with categories. In fact, it uses some of the item tag system, so it actually disables item tagging.

Nick, you know I've done this of course, you and I were talking about it.

However, I'm having one issue I was hoping someone might be able to address.

When viewing the tags i.e index.php?option=com_k2&view=itemlist&task=tag&tag=[tag] it simply displays the item with the id of the category I want it to display. I'm sure it's fairly easy to fix, I just can't for the life of me find where that part of the code is.

Basically, I need to change the tag task from displaying items, and make it display categories instead. Once that's done, the tag conversion is complete.

I'd appreciate any help anyone can offer. Thanks :)

Please Log in or Create an account to join the conversation.

More
14 years 3 weeks ago #85055 by Lloyd Sims
Replied by Lloyd Sims on topic Tagging categories
Problem solved.

I simply had to duplicate (somewhat) the category task and put it into the tag task. Create a couple of functions and treat tagged categories as child categories under that tag for display purposes.

Please Log in or Create an account to join the conversation.

More
14 years 3 days ago #85056 by Lloyd Sims
Replied by Lloyd Sims on topic Tagging categories
For anyone else that is interested, I have now completed a category tagging system. It is a conversion of the item tagging system however, and both can not be used simultaneously. I actually finished this a couple weeks ago, but forgot to share it.

Not tested with SEO enabled. I believe a link will need editing in of the files for that. I do actually intend to look into this, but haven't had the time yet.

The hack is amateur at best, I am not a coder. In fact I only got Joomla/K2 to create this for Nick. Although, I have now decided to use Joomla/K2 for another project as I was impressed. The code is messy and is likely 'over-coded', feel free to clean it up.

There is also a file with sql commands included that will create a backup of the current tag_xref table and then move an items tags to that specific items category. It can not be imported directly into the db though. Please copy and paste the relevant commands - this is to ensure you read the comments and understand what each query is doing - in case you need to revert! The field rename sql is required, but the rest isn't. If you don't want your item tags to port over to the category, then empty the tags table and only execute the "*** Renames itemID to catID for the code" query.

The tag system must be set to selective in global parameters for it to be fully functional on the edit/new category page.

I haven't taken any time into making this into anything you can install. The attached simply includes the edited files, anything I've edited is commented as follows \\Goon or <-- Goon (with !) just search the code for Goon. Anything major has comments on it, and additions have a \\Goon end.

I don't intend to take this project any further unless Nick requires as such. This hack may serve as an adequate base for someone else to do so though.

And, if for some daft reason you decide to overwrite your own files with these on a live server. For the love of god, backup the originals beforehand!
Attachments:

Please Log in or Create an account to join the conversation.

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 days ago #85057 by Nick
Replied by Nick on topic Tagging categories
you are the man. Shame that i didn't get around testing this. I HATE college and i HATE ASHER ROTH.

Lloyd Sims said:For anyone else that is interested, I have now completed a category tagging system. It is a conversion of the item tagging system however, and both can not be used simultaneously. I actually finished this a couple weeks ago, but forgot to share it.
Not tested with SEO enabled. I believe a link will need editing in of the files for that. I do actually intend to look into this, but haven't had the time yet.

The hack is amateur at best, I am not a coder. In fact I only got Joomla/K2 to create this for Nick. Although, I have now decided to use Joomla/K2 for another project as I was impressed. The code is messy and is likely 'over-coded', feel free to clean it up.

There is also a file with sql commands included that will create a backup of the current tag_xref table and then move an items tags to that specific items category. It can not be imported directly into the db though. Please copy and paste the relevant commands - this is to ensure you read the comments and understand what each query is doing - in case you need to revert! The field rename sql is required, but the rest isn't. If you don't want your item tags to port over to the category, then empty the tags table and only execute the "*** Renames itemID to catID for the code" query.

The tag system must be set to selective in global parameters for it to be fully functional on the edit/new category page.

I haven't taken any time into making this into anything you can install. The attached simply includes the edited files, anything I've edited is commented as follows \\Goon or <-- Goon (with !) just search the code for Goon. Anything major has comments on it, and additions have a \\Goon end.

I don't intend to take this project any further unless Nick requires as such. This hack may serve as an adequate base for someone else to do so though.

And, if for some daft reason you decide to overwrite your own files with these on a live server. For the love of god, backup the originals beforehand!

Please Log in or Create an account to join the conversation.

More
14 years 1 day ago #85058 by David R.
Replied by David R. on topic Tagging categories
Nick,
While I can understand why some people might want to have this sort of extension, lobotomizing the existing item tag system in favor of category tags isn't the way to go, although I admire Lloyd's ingenuity, especially considering he claims not to be a programmer.

In terms of the schema i think you were on the right track originally. Adding that would be a lot of code, although I have a hard time understanding why this was important to you to do. What exactly about tags wouldn't work for you? Does your site have a lot of categories, and or nested categories?

Please Log in or Create an account to join the conversation.

More
14 years 1 day ago #85059 by Lloyd Sims
Replied by Lloyd Sims on topic Tagging categories
Nicks has a few categories, and then several sub-categories each with a varying amount of items within them. However, the unique aspect is that the sub-category is a collection of items. Yes, the items are unique in themselves, but they form part of a collection and don't function as well on their lonesome.

The reason he needs tagging on categories is simply a single item is not a complete set. By using the tag item feature you'd find the 5th in the collection. By having category tags, you find the collection itself.

A full collection couldn't be posted into a single item, as additions are made to said collection at any given time and need to appear on the front-page as new additions. Similarly, more than one person may contribute to the collection. Each item has a picture (and that's important!) and extra fields. So really merging them into one item wouldn't be feasible anyway.

Given there was no need for the item tagging system on his site, I felt it would be easier to port it across as opposed to create a new system to run alongside it... which is what I did.

Hopefully that clears things up a little as to why he required what he did.

David R. said:Nick, While I can understand why some people might want to have this sort of extension, lobotomizing the existing item tag system in favor of category tags isn't the way to go, although I admire Lloyd's ingenuity, especially considering he claims not to be a programmer. In terms of the schema i think you were on the right track originally. Adding that would be a lot of code, although I have a hard time understanding why this was important to you to do. What exactly about tags wouldn't work for you? Does your site have a lot of categories, and or nested categories?

Please Log in or Create an account to join the conversation.

More
14 years 1 day ago #85060 by David R.
Replied by David R. on topic Tagging categories
I guess it comes down to how you look at things. One alternative to this would have been to use a user defined field for the collection name rather than an attribute. That method still would probably have required some customization, but it's an interesting problem. I guess your application is one that people might point to when they argue for allowing categories to be related many-to-many, although your grafting on of a "category tag" is an interesting solution to that problem.

Lloyd Sims said:Nicks has a few categories, and then several sub-categories each with a varying amount of items within them. However, the unique aspect is that the sub-category is a collection of items. Yes, the items are unique in themselves, but they form part of a collection and don't function as well on their lonesome.
The reason he needs tagging on categories is simply a single item is not a complete set. By using the tag item feature you'd find the 5th in the collection. By having category tags, you find the collection itself.

A full collection couldn't be posted into a single item, as additions are made to said collection at any given time and need to appear on the front-page as new additions. Similarly, more than one person may contribute to the collection. Each item has a picture (and that's important!) and extra fields. So really merging them into one item wouldn't be feasible anyway.

Given there was no need for the item tagging system on his site, I felt it would be easier to port it across as opposed to create a new system to run alongside it... which is what I did.

Hopefully that clears things up a little as to why he required what he did.

David R. said:Nick, While I can understand why some people might want to have this sort of extension, lobotomizing the existing item tag system in favor of category tags isn't the way to go, although I admire Lloyd's ingenuity, especially considering he claims not to be a programmer. In terms of the schema i think you were on the right track originally. Adding that would be a lot of code, although I have a hard time understanding why this was important to you to do. What exactly about tags wouldn't work for you? Does your site have a lot of categories, and or nested categories?

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum