This is a handy little guide, if you want to change the way that your Tag Results page is displayed.
As default, when you click on a Tag Link in a K2 Item, it will produce a page showing all full items which have that particular tag.
Now, if you Items contain a lot of information or you have a lot of Items with the same Tag, you will end up with quite a long list.
This little guide will explain how to reduce the displayed data to show just a snippet of the Item information plus add a bit of extra information.
Firstly, we are going to have to modify the generic.php file, this is located on components/com_k2/templates/
Now, If you do not want to modify this core file, then you can create a new K2 template first.
K2 Template Creation
- In your Joomla template, we need to create a new folder.
On your server, navigate to templates/YOURTEMPLATE/html
- Create a new folder called com_k2
- Go to components/com_k2 and copy the folder called templates
- Paste this folder into templates/YOURTEMPLATE/html/com_k2
- Go to templates/YOURTEMPLATE/html/com_k2/templates and rename the folder called default to something more meaningful for you. If you keep it as default, it will only cause you confusion later on.That is all the K2 template files copied, now for the css.
- Go to components/com_k2/css and copy the k2.css file.
- Paste the file to templates/YOURTEMPLATE/cssCss file is now copied, now for the image folders.
- Goto components/com_k2 and copy the images folder.
- Paste the file to templates/YOURTEMPLATE/html/com_k2
You should now have all the required files in your Joomla template that will over ride the default K2 template.
All you need do now, to use this template, is to set it within the Category Parameters in the K2 Control Panel.
At this stage, the K2 default template will always be used for all new Categories that are created, but you can of course select your new K2 template.
Modifying Your Tag Results
Now we have our k2 template over ride in plate, we can modify our files without affecting the core files.
This enables use to be completly flexible in the layout of pages so that they can differ from category to category.
Lets now modify the Tags Result page.
Setup Word Limit
- To do this, we need to open the generic.php located in templates/YOURTEMPLATE/html/com_k2/templates/YOURK2TEMPLATE
- We need to modify the code, which can be seen in the following image.
- You will see that I have commented out (yellow) the original code on line 80 and added in some new code on line 81.
Notice, the red circle around the number 30. This sets the introtext to display 30 words, you can of course change this to how you want.Now, instead of displaying a full item, you will just have the set number of words displayed.
Remove Item Images
If you do not want your Item Images to be displayed, to keep this view clean and simple, then you will need to remove or comment out some more code. The image below shows which code is used.
Add Page Title
This next tip will display a page title which shows which tag name the accompanying list of items are related to.
The image below shows the code we will be looking at.
Add in the code on Line2 41.
I have wrapped this in a H2, but you could add any class you wish to style it.
So what does this all look like?
The image above shows our new Page Title “Displaying items by tag:” and “tag1” was the tag selected, of course some padding/margins could have been used 😉
Our ItemImage is removed and our text limited.
One further thing that could be done, is to move the “Read More” from next to the “Published In” and place it at the end of the intro text.
Perhaps a little something for you to play with.
Hopefully you found this quick guide useful, comments are welcome.
Original artlicle: http://community.getk2.org/profiles/blogs/modifying-the-tags-results