Keyword

Little help with the php please

  • kire timov
  • kire timov's Avatar Topic Author
  • Offline
  • Senior Member
More
13 years 11 months ago #89727 by kire timov
Little help with the php please was created by kire timov
Hi,I am trying to make some modifications to the k2 component. Actually i am trying to add character limit
instead of word limit for the intro text for category listing, to
achieve better control over the content. For me this is essential to my
project and i have some deadlines i require help, however this would be
very useful for every other k2 user, i wonder why it's not there by
default.So...There is a tutorial on the k2 forums on how to add character limit to to the k2 content module but not for the component actually...So i tought i can somehow use that code but add it to different places.This is the tutorial to add the char limit to the module:link to the attachment:http://weblogicxindia.in/k2store/index.php?option=com_k2&amp;view=item&amp;task=download&amp;id=14Step 1Download the attached file below , and rename it as charlimit.php and add it to ROOT/components/com_k2/helpers/Step 2The only hack you have to do is adding a param to the k2 content module. Open the mod_k2_content.xml fileadd this param after line 82. (that is after the param for word limit)<param name="itemIntroTextCharLimit" type="text" size="4" default=""label="Introtext character limit" description="Leave blank to diasble.If you enable this option, all html tags from the text will be cleaned upto make sure the html structure of the site does not brake." />Save it. and Go to the backend, open the k2 content module in the back end
and set the character limit. if you set the character limit, then this
will be taken and not the word limit. leave this blank, if you want to
disable this.Step 3Create a template over ride for the module k2 content. Create the module structure inside the html folder of your template.Here is a brief for those who do not know about the template overrides:
Inside the html folder in your template (if u dont find, create a folder
and name it as html), create a folder named mod_k2_content. Then copy
the content from ROOT/modules/mod_k2_content/tmpl to the newly created
folder in your template.Open the default.phpadd this line below this defined('_JEXEC') or die('Restricted access');require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'charlimit.php');and in line around 69, find these code&lt;?php if($params-&gt;get('itemIntroText')): ?&gt;&lt;?php echo $item-&gt;introtext; ?&gt;&lt;?php endif; ?&gt;replace this code with:&lt;?php if($params-&gt;get('itemIntroText')):if ($params-&gt;get('itemIntroTextCharLimit')) {$item-&gt;introtext = K2charUtility::charLimit($item-&gt;introtext, $params-&gt;get('itemIntroTextCharLimit'));} else {$item-&gt;introtext = $item-&gt;introtext;}echo $item-&gt;introtext;endif;?&gt;That's it. Your are done.I have done Step 1I have done Step 2Add this param after line 82. (that is after the param for word limit)&lt;param name="itemIntroTextCharLimit" type="text" size="4" default=""label="Introtext character limit" description="Leave blank to diasble.If you enable this option, all html tags from the text will be cleaned upto make sure the html structure of the site does not brake." /&gt;but i did not added the code in mod_k2_content.xml but instead in category.xml located in ROOT/administrator/components/com_k2/models/This added the option in the backend successfully(under Item view options in category listings) and indeed there is an option right after the word limit to choose character limit.I have NOT done Step 3In the tutorial he says:Open the default.phpadd this line below this defined('_JEXEC') or die('Restricted access');require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'charlimit.php');and in line around 69, find these code&lt;?php if($params-&gt;get('itemIntroText')): ?&gt;&lt;?php echo $item-&gt;introtext; ?&gt;&lt;?php endif; ?&gt;replace this code with:&lt;?php if($params-&gt;get('itemIntroText')):if ($params-&gt;get('itemIntroTextCharLimit')) {$item-&gt;introtext = K2charUtility::charLimit($item-&gt;introtext, $params-&gt;get('itemIntroTextCharLimit'));} else {$item-&gt;introtext = $item-&gt;introtext;}echo $item-&gt;introtext;endif;?&gt;For the module it's in that template over ride in the default.php But the problem is i don't know where to add the code for Item view options in category listings in the k2 component.Thanks for helping! I hope this will help to other people as well.

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

More
13 years 10 months ago #89728 by hasan celiktas
Replied by hasan celiktas on topic Little help with the php please
Does anybody know the answer? I need it too...

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

  • kire timov
  • kire timov's Avatar Topic Author
  • Offline
  • Senior Member
More
13 years 10 months ago #89729 by kire timov
Replied by kire timov on topic Little help with the php please
hi Mate.. a somehow managed to do it but did not helped. if you need it to limit the character limits (because you have aligment problem in the category view) than the best solution would be to add fixed heigh for the intro text or whatever you need.. because with char limit this is not solved..problems with the font styles of the template and than again you have aligment problem etc..

another solution is (worked for me)
go to \com_k2\templates\default\category_item.php
search forand change it toexperiment with the height .. whatever height suits you.

I hope this helps

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


Powered by Kunena Forum