Keyword

How Fix - Introtext - Word limit for multiple categories

  • L Nathan
  • L Nathan's Avatar Topic Author
  • Offline
  • New Member
More
13 years 7 months ago #94341 by L Nathan
Anyone know to fix this problem ??

 

When i select multiple categories for the Home Menu for exemple, the introtext dont work.

 

How can i aply the wordlimit for all categories ?

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

More
13 years 7 months ago #94342 by David Pérez
Hey, I just found a way to solve the problem, I don't know if by solving this i messed up with other things (I don't think so), so do it at your own risk. If any K2 developers can give a hand it would be highly appreciated anyway ;)

 

So, I think the problem is in the item.php file that you can find under "/components/com_k2/models/". If you edit that file, around line 175 you should find something like this:

 

if ($item->params->get('catItemIntroTextWordLimit') && $task=='category'){ $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit')); }

 

if you delete the part about the task, leaving it like this, it should do the trick:

 

if ($item->params->get('catItemIntroTextWordLimit')){ $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit')); }

 

Anyway, If you don't feel like editing the file on your own, here I upload the file edited by myself from the last K2 release. Of course don't forget to make a backup of the old item.php file.

If you want to have a look, here's the webpage i'm building, as you'll see there are 2 articles of 2 categories, first with about 60 words and second with 100

unocerouno.co.cc/index.php?option=com_k2&view=latest&layout=latest&Itemid=13&lang=es

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

More
13 years 7 months ago #94343 by Jiliko.net
Hi David,

 

Your solution surely works but should be done in another file than this one. This should be placed in the category_item.php K2 template file. Why ?

 

- No modification of K2 core file, so no problem with K2 updates

- Use of a template overriding, so you can just enable this "fix" to the categories using this template. This means you can create a specific K2 template for your multi categories menu item and enalbe the fix in it.

 

Cheers,

 

Olivier

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

More
13 years 7 months ago #94344 by David Pérez
Hi Olivier,

 

Yeah, I know editing the core files is just a temporary fix until a new version is released and that, by that time, the patch will probably be necessary again, but there's no way of doing this in any templates (or at least i don't know how to do it), as you need to access category class fields to truncate the string, and this is against the rules of templates, that should limitate to show the content given to them by the view.

But, this thing got me thinking and I realized i made a mistake yesterday (programming at 6 in the morning is not the safest thing to do), so i found the real problem is not the item itself (in fact editing the item.php itself it's wrong), but the 'latest' view, (/components/com_k2/views/latest/view.html.php) and the itemlist view (/httpdocs/components/com_k2/views/itemlist/view.html.php).

In both files, do a search and look for the calling to the funcion 'prepareItem' and set last parameter to 'category'

 

in latest view:

line 99, instead of 

$category->items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $category->items[$i], 'latest', '');

you should use

$category->items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $category->items[$i], 'latest', 'category');

 

line 103, instead of 

$category->items[$i] = $itemModel->prepareItem($category->items[$i], 'latest', '');

should be

$category->items[$i] = $itemModel->prepareItem($category->items[$i], 'latest', 'category');

 

In itemlist

line 274, instead of

$items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $items[$i], $view, $task);

should be

$items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $items[$i], $view, 'category');

 

and finally line 278, instead of

$items[$i] = $model->prepareItem($items[$i], $view, $task);

replace it by

$items[$i] = $model->prepareItem($items[$i], $view, 'category');

 

Editing those two views made it all work for now, hope that will help anyone, I still don't understand the underlying problem, since I'm just a beginner in this K2 world

 

Good luck,

 

David

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

  • L Nathan
  • L Nathan's Avatar Topic Author
  • Offline
  • New Member
More
13 years 7 months ago #94345 by L Nathan
UAUUUU!!

 

FINALLY!!

 

I've been tried Days to fix this!

 

THANKS! o/

 

Really.. Thanks.

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

More
13 years 7 months ago #94346 by Ruud
I think Olivier is referencing to this when he mentions not to edit core files: simon.getk2.org/index.php?option=com_k2&view=item&id=91:templating&Itemid=1. This way you get to implement your changes without having to worry about losing them during K2 updates.

 

I am very interested in your solution although I fail to understand it. May Olivier could shed some light on it? And is this a better solution than proposed here: community.getk2.org/xn/detail/3536014:Comment:97681? And how do we make sure that this feature is included in a feature release?

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

More
13 years 4 months ago #94347 by David Spennacchio
Replied by David Spennacchio on topic How Fix - Introtext - Word limit for multiple categories
Wow - genius.  Been looking around for a long time for this - and making those modifications in the files really helped!  You can see this in action on my homepage - using K2 latest items via multiple categories.

www.allaroundfit.com

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


Powered by Kunena Forum