K2 Tip: How to show read more when necessary

The default behavior for K2 is to display the read more button at all times (if selected in the parameters), even if there is no more content. This is not good for blogs where some posts may have the complete article in the listing. A quick fix for this is to edit the category_item.php file, but first you want to make sure to create a sub template within your template directory. To learn more about sub-templates, you can checkout the documentation here: http://getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Edit templates/yourtemplate/html/com_k2/default/category_item.php.

Search for

<?php if ($this->item->params->get('catItemReadMore')): ?>

Change it to:

<?php if ($this->item->params->get('catItemReadMore') && $this->item->fulltext): ?>

We are adding an and variable check to the if statement to check if the items fulltext has a value. If so, the read more link will appear.

That’s it!

Note: If you would like to do it the quick and dirty way, you can edit components/com_k2/templates/default/category_item.php, but this will be overridden when you update K2.

Be Sociable, Share!
Tarik Assagai
Tarik (@tarik916) is a web developer and owner of ACS Digital Media, a Sacramento based web development agency specializing in open source CMS systems. If you are looking for support for your current or upcoming projects, visit www.acs-digital.com.

Leave a Reply