- Posts: 955
COMMUNITY FORUM
K2 item in Multiple Categories
- Simon Wells
-
Topic Author
- Offline
- Platinum Member
Please Log in or Create an account to join the conversation.
- Ivan Descartes
-
- Offline
- New Member
- Posts: 10
So how to implement? Here is the best way:
First, from the item creation, it can be assigned to multiple categories. 1 category is set as the primary category, and this category is stored in catid in the database (for compatibility). All other categories are stored in a new database table that maps items to categories by paths. The schema for this table:
ID (primary key) ItemID CatID PathID (optional)
The ID is just the primary key. The ItemID stores the article ID. The cat ID stores the CatID. The PathID is an optional parameter that reflects if this is path 1, path 2, path 3, .... to get to this item.
Any time an item is created, we make unique entries for each category assignment. This puts the database load on the item creation rather than search (if we had put all of the categories comma-separated in the original items table). When a category listing is requested, we just find all of the items in this Paths table that match, and list them. Other modules that use K2 should start using this table.
So for URLs, there is an SEO way and a non-SEO way, I want to highlight both, and suggest the SEO way.
SEO way: only 1 url per article. Unless some magical cookies or database are used, the page cannot reflect which category the user arrived by.
non-SEO way: multiple urls per article. This allows the URL to reflect the category that the viewer reached the item by. However, it also means that there are multiple URLs for the same item. This could be done simply by appending the "path" to the end of the URL to allow K2 breadcrumbs to properly display the path, or the whole url would be set correctly (the latter being preferable).
Let me know if this makes sense. The feature is quite important if K2 wants to be THE content solution.
Please Log in or Create an account to join the conversation.
- Ivan Descartes
-
- Offline
- New Member
- Posts: 10
Please Log in or Create an account to join the conversation.
- FeSys
-
- Offline
- Elite Member
- Posts: 262
I guess this is the easiest way for now.. Give it a try.. works for me fine.
Please Log in or Create an account to join the conversation.
- Danny Malouin
-
- Offline
- New Member
- Posts: 5
Has this been adressed ?
I would like to assign items to more than one category as well.
Thanks,
Danny
www.6degres.ca
Évoluez sur le 3W!
Please Log in or Create an account to join the conversation.
- Oceanwatcher
-
- Offline
- Elite Member
- Posts: 175
It might just be that we are used to think in a certain way and we got used to this by using a different software/system. I am also using WordPress for a couple of sites and like some of the things there a lot. And I am used to the category system there.
But maybe it is better to switch this for the tags. Maybe that is a more flexible way of doing it? Opinions?
Please Log in or Create an account to join the conversation.
- FidelGonzales
-
- Offline
- Premium Member
- Posts: 95
While there are unique and very favorable advantage to using K2, the aforementioned issue is a huge drawback to many of its other unique features, one that Fotis has no interest in solving, as per blog posts and Tweets. I am certain there is some purpose to his reasoning, but I have yet to hear it nor cannot fathom any reason that would justify remaining the course on this methodology.
Personally, if tags were given the ability to possess content description, photos and process Joomla plugins, the problem would be solved and produce some beautiful content, an intuitive interface and some excellent SEO.
With that said, here's a semi-related topic I created.
community.getk2.org/forum/topics/process-joomla-plugins-in-k2?commentId=3536014%3AComment%3A66364
Svein Wisnaes said:I have a case right now where I would love to be able to set several categories for one article. For now, it has been solved with the use of tags, and I suspect this is how we will have to use it in the future.
It might just be that we are used to think in a certain way and we got used to this by using a different software/system. I am also using WordPress for a couple of sites and like some of the things there a lot. And I am used to the category system there.
But maybe it is better to switch this for the tags. Maybe that is a more flexible way of doing it? Opinions?
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
How about putting the category id's in a field like the xtra filelds and teach the core to parse them out.
Its changing the way things work - not likely to happen unless a module like followeyes points to can do it for you
Ivan Descartes said:Another way, which is much easier: Add catid2, catid3 .... catidx to the k2_items table. This would work well, but means that K2 will dictate how many categories an item can be added to. I think 3 categories is a reasonable limit. Of course, this results in a performance hit, since all of the fields in ITEMS must be checked for a listing, even if an item is only listed in 1 category. So in the worst case, where all items appear in just 1 category, there is a 3x hit. In the best case, where all items are in 3 categories, it is the same cost as the previous suggestion.
Please Log in or Create an account to join the conversation.
- Danny Malouin
-
- Offline
- New Member
- Posts: 5
Maybe the developpers would like to say a word ?
Danny
Please Log in or Create an account to join the conversation.
- Abdul Muhaymin
-
- Offline
- Junior Member
- Posts: 28
I have added table, now how to bring selecting option in backend, pls solve it. Where, in which page we have to edit changes.
Thanks
Abdul Muhaymin
Ivan Descartes said:Another way, which is much easier: Add catid2, catid3 .... catidx to the k2_items table. This would work well, but means that K2 will dictate how many categories an item can be added to. I think 3 categories is a reasonable limit. Of course, this results in a performance hit, since all of the fields in ITEMS must be checked for a listing, even if an item is only listed in 1 category. So in the worst case, where all items appear in just 1 category, there is a 3x hit. In the best case, where all items are in 3 categories, it is the same cost as the previous suggestion.
Please Log in or Create an account to join the conversation.
- Oceanwatcher
-
- Offline
- Elite Member
- Posts: 175
As I am not a programmer, it is a little bit difficult for me to look at things deeper down, but I did a little experiment.
I have a couple of sites that run on WordPress, and in WP, you can easily add an article to as many categories as you want. So I checked the database.
In the wp_posts table, there is something about category, but it is not used. Instead, there are three tables
wp_terms
wp_term_relationships
wp_term_taxonomy
Checking these makes it clear that the terms are merely a form of tags that are grouped into different functions according to the taxonomy table (forgive me for describing this in laymans terms - non-programmer, remember? :-D ).
So depending on the taxonomy, a term can be either a "category", a "link_category" or a "post_tag".
I have no idea how big hit the database in WP takes by doing it this way, but it can not be too bad as WP runs with a lot of big sites...
Please Log in or Create an account to join the conversation.
- krmr
-
- Offline
- Senior Member
- Posts: 61
Using tags to organise content is for sure lot more flexible, but there comes the tags view in k2, that is so much more limited than the catview. No author is displayed in tags view (the generic.php template) for example? And that is simply not acceptable in certain site formats. like a publication
Please Log in or Create an account to join the conversation.
- kiril Hristov Yovev
-
- Offline
- Junior Member
- Posts: 37
(SOrry for my bad english)
Please Log in or Create an account to join the conversation.
- FidelGonzales
-
- Offline
- Premium Member
- Posts: 95
kiril Hristov Yovev said:with the component "Zoo" you can add item un multiple categories. I think that the k2 developers should do something about this... this is a must have feature... it is really really important. When few months ago i've opened new thread about this you've said to me that this problem is solved with the tags-but it's not the same. There are huge diferenses between tags and multiple categories... DOn't understand me wrong-i love k2.....but i really miss this great feature...
(SOrry for my bad english)
Please Log in or Create an account to join the conversation.
- HankBrown
-
- Offline
- New Member
- Posts: 9
Apparently this guy, named Jason Hart, did some work on an own MultiCat-solution for K2 already. Sure, it is only an Aplha-Version and only in combination with K2 v.2.2 but it might be a good start for a complete solution to our all problem ... don't you think so too? I am unfortunately not a professional progammer myself but maybe you guys or the people of the K2-development team can give this guy Jason Hart a hand in what he already has started ...
Here is his website with the current Alpha-Version of K2 MultiCat as download: www.developmii.com/downloads/k2-multicat.html
Please Log in or Create an account to join the conversation.
- Tafadzwa Makura
-
- Offline
- New Member
- Posts: 10
I haven't tried this though but i'm sure by adding the (Related Items by Tag) code block in the category list view i can also make all items that share one of their tags with the current Category appear in that Category's list! The major drawback is that users won't be able to user their own custom tags.
Please Log in or Create an account to join the conversation.
- Tafadzwa Makura
-
- Offline
- New Member
- Posts: 10
After a user has created their item they choose the primary category they want their item to belong to, this is where the reference article can be stored. Just like tags a user can then add as many multiple Secondary Categories as they need. Secondary Categories only pull the refrence item directly from it's primary Category without copying or moving it! If the Item is deleted from it's primary category then the Secondary categories will automatically stop linking to it because it disappears with its stored secondary Category (just like tags).
In the category list a php script will fetch the value of the current primary category title lets call it ($currentPrimCatTitle) and then pull any other items whose secondary category title ($item->secCatTitle ) matches ($currentPrimCatTitle). These articles will then be displayed in the cartegory list with all the other articles that share that Category. This system already works with tags I'm sure it will be much easier to intergrate.
Advantages.
1.) Only one copy of an item will be used to create multiple instances of it in different cartegories.
2.) The creation/deletion and edition of Secondary Categories will happen dynamically making sure they remain synced with their Primary Category Counterparts and reducing the workload on the users part.
3.) No additional Data is written to the Database outside the item's database row when an item is added!
4.) The system is intuitive, meaning a user/editor/admin can easily add and remove Secondary Categories from their current item.
5.) Changing an item's Primary Category will not break it's connection with it's current Secondary Categories (Just like Tags)
6.) Parameters and ACL can also be used to block specific Secondary Categories from being attached to a none Admin User's Item i.e (FAQ and Admin Secondary Categories will not be added to to a None Admin Item)
If used please credit this idea/concept to me!
Tafadzwa Makura said:
I use tags! By giving tags similar names to categories and locking them so that the user cannot add their own custom tags I then allow users to add their article to one "primary" category in the category list and choose as many "category-tags" as they want in the tag list! This means that if a user/publisher publishes their article entitled "Major Health Issues Sportsman and Artists Face" and they want it to appear in the Health, Sports and Arts categories they will have to choose the primary category in the category list which in this case could be the Health category, this is where the article will be stored and linked to. If the user however adds the Sports, and Arts tags to their article the article will also appear in these categories as related items in the item layout of the Sports and Arts categories!
I haven't tried this though but i'm sure by adding the (Related Items by Tag) code block in the category list view i can also make all items that share one of their tags with the current Category appear in that Category's list! The major drawback is that users won't be able to user their own custom tags.
Please Log in or Create an account to join the conversation.
- Tafadzwa Makura
-
- Offline
- New Member
- Posts: 10
Please Log in or Create an account to join the conversation.
- Nick
-
- Offline
- Elite Member
- Posts: 190
As for the back end you can have a new drop down appear after you select a category. I have over 200 categories so a tag based system or a simple list system wouldn't work for me (unless the list is inside a frame)
It's really not hard to do guys.. I could code it in several days.. i'm just working on college stuff right now.
Please Log in or Create an account to join the conversation.
- juju
-
- Offline
- Premium Member
- Posts: 119
Thanks ;)
Please Log in or Create an account to join the conversation.