Keyword

Tag-Template

  • razen
  • razen's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 10 months ago - 7 years 10 months ago #158981 by razen
Tag-Template was created by razen
Hi,

I try to create a template which sort out several items in case they're the wrong ones.

Let me explain: Right now I got two categories with lots of subcategories and items in it. The items are also tagged well, but the tags are sometimes used in both categories. Actually, I dont want items from both categories to be mixed. AN alternative I found is to create menu-items for all tags with a category-filter, but with so many tags that's a pain.

Without the menu-item for tags, I realised the url got the category in where you came from:

website.com/category1/itemlist/tag/TagName
website.com/category2/maybe_another_subcategory/itemlist/tag/TagName

No my plan would be, to get the URL, read out the main category from it and on case the found category is NOT the topcategory of an item, it shouldn't be displayed from the template.

I know that's not the correct usage of templates, but so far I can't think of another easy way.

Now the questions:
1. How can I get the actual URL and read out the category?
2. How to filter the items with the wrong top-category? All I found hit this in the tag.php-template, but I guess I have to add some more stuff :D

<?php foreach($this->items as $item): ?>

3. Is there're a way to edit the url, from
website.com/category2/maybe_another_subcategory/itemlist/tag/TagName
to
website.com/category2/tag/TagName
The subcategorys and itemlist is not really necessary from my part of view...

Thanks for the help :)
Last edit: 7 years 10 months ago by razen.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #158997 by Krikor Boghossian
Replied by Krikor Boghossian on topic Tag-Template
You can use K2's advanced SEF to create a new pattern for tag URLs.
You can then, create an empty K2 Categories menu item and call it eg: content.
This will create a /content/tag/tag-name pattern.

This will be a new pattern but you won't have to manually manipulate each link.

If you want to build a manual pattern based on the current category, you need to edit the item.php file (and the category_item.php file if the tags are shown in the category) and based on the item's category id build the link manually.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • razen
  • razen's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 10 months ago #159000 by razen
Replied by razen on topic Tag-Template
As far as I can see this only answer my third question, does it?

I created a K2-Category-Menuitem without any category selected. Then blicked on a tag but the itemlink was still the long one - what else do I have to setup?

What about the other two questions?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #159021 by Krikor Boghossian
Replied by Krikor Boghossian on topic Tag-Template
Did you enable K2's advanced SEF?
This will create the new pattern.

If that does not work for you, you can manually alter the link where the tags appear (item.php, category_item.php etc ) in order to build a manual link.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • razen
  • razen's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 10 months ago #159022 by razen
Replied by razen on topic Tag-Template
Nice, that worked with the tag-url.

What with the first two questions - can you help there?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #159039 by Krikor Boghossian
Replied by Krikor Boghossian on topic Tag-Template
- You can get the item's direct category ($item->category->name, $item->category->link, $item->category->link), you can construct a manual link based on the category, but with K2's advanced SEF, I do not think this is needed.

- Unfortunately sorting the items per category is only available if you map
that tag into a menu item.

You can edit the tag.php file and based on the category hide the item but this will lead into inconsistent layouts.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • razen
  • razen's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 10 months ago #159279 by razen
Replied by razen on topic Tag-Template
Ok I learned a lot so far - I have to map the tags through a menu-item to make things work, but:

I got two main categories CatA and CatB and the tags are used for items in both categories.

Since I would like to have the domain like the following:

domain.com/catA/tags/tag/name-of-the-tag
domain.com/catB/tags/tag/name-of-the-tag

I created two menu-items to map the tag through them, one as sub-menuitem for category A and one as sub-menuitem for category B, but whereever I press on a tag, it always map the tag through the menuitem of category B (probably looking for the first/last one and if it got it it stop searching and uses it).

So is there a way to map through different menuitems depending on which category you're in right now?

Beside this: Is there a way to get the URL-Path of the page you came from?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #159304 by Krikor Boghossian
Replied by Krikor Boghossian on topic Tag-Template
This won't work.
The last instance of the tag will always be respected.
You can manually add a parameter to the URL (itemID) in your overrides so a menu item's settings are enforced.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • razen
  • razen's Avatar Topic Author
  • Offline
  • Senior Member
More
7 years 10 months ago #159316 by razen
Replied by razen on topic Tag-Template
"You can manually add a parameter to the URL (itemID) in your overrides so a menu item's settings are enforced. "

Erm, sorry but I don't quite understand what you're trying to say here, can you explain it a bit?

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 10 months ago #159335 by Krikor Boghossian
Replied by Krikor Boghossian on topic Tag-Template
Actually that was silly of me, there is a template 'hack' way in order to change the appearance of tags (the title, the layout etc) without the need of menus, although menus are preferable.

You can use GET variables.
php.net/manual/en/reserved.variables.get.php

A simple example in the tag template would be:
if( isset($_GET['ref']) && $_GET['ref'] === 'catalog') $title = 'TITLE 1';

This means that tags that have ?ref=catalog in their URL can have a different layout or main title in your case.

The ?ref=XXX can be added in the item.php file where tag are populated. Based on the category's ID you can populate the link.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum