Keyword

How to limit item description characters?

  • Yvonne
  • Yvonne's Avatar Topic Author
  • Offline
  • New Member
More
11 years 9 months ago #107909 by Yvonne
Hi all, I am wondering how to limit the characters of K2 item description? Here is my situation: I created "Home" menu which will direct to K2 categories. So on my homepage is K2 categories view, but the items will display all the description characters and looks messy. I tried to change the parameters on K2 category setting. This works when click the category menu, but not work on homepage.
Thanks!

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

  • Yvonne
  • Yvonne's Avatar Topic Author
  • Offline
  • New Member
More
11 years 9 months ago #107910 by Yvonne

Yvonne wrote: Hi all, I am wondering how to limit the characters of K2 item description? Here is my situation: I created "Home" menu which will direct to K2 categories. So on my homepage is K2 categories view, but the items will display all the description characters and looks messy. I tried to change the parameters on K2 category setting. This works when click the category menu, but not work on homepage.
Thanks!

Does K2 just support one category setting and not work with more than one categories? What I means is that I selected more than one categories content to display on my home page. In that case the introtext will display all the words on my home page even though I set the limitation parameter on each category.
Can somebody help? Thanks!

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

More
11 years 9 months ago #107911 by Daniel Hristov
Replied by Daniel Hristov on topic Re: How to limit item description characters?
Hi!
In your category item template you can use the following code:
<?php if($this->item->params->get('catItemIntroText')): ?>
<?php
if($this->item->params->get('catItemIntroTextWordLimit') == ''){
$itemdesc = $this->item->introtext;
$itemdesclimit = '520';
if (!empty($itemdesc)) {
$thisitemdesc = strip_tags($itemdesc);
$thisitemdesc = substr($thisitemdesc, 0, $itemdesclimit);
$thisitemdesc = substr($thisitemdesc, 0, strrpos($thisitemdesc, ' ')).'...';
} else {}
} else {
$thisitemdesc = $this->item->introtext;
}
?>
<?php echo $thisitemdesc; ?>

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

  • Yvonne
  • Yvonne's Avatar Topic Author
  • Offline
  • New Member
More
11 years 9 months ago #107912 by Yvonne
Thanks Daniel!
Could you tell me more particular? Could you tell me which file I need to paste these code to?

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

More
11 years 9 months ago #107913 by Daniel Hristov
Replied by Daniel Hristov on topic Re: How to limit item description characters?
If you want to create custom K2 template, you should copy the content of [ components/com_k2/templates ] (four files and a 'default' folder) to the 'html' folder in your template directory (base_dir/templates/your_temp_name/html/com_k2 - if you wish, you can give a different name for your new k2 template). The file which you have to edit to set the desired description is category_item.php
Search for:
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php echo $this->item->introtext; ?>
</div>
<?php endif; ?>
and replace it with the code I gave before.

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

More
11 years 5 months ago #107914 by jetlininja
Replied by jetlininja on topic Re: How to limit item description characters?

Daniel Hristov wrote: If you want to create custom K2 template, you should copy the content of [ components/com_k2/templates ] (four files and a 'default' folder) to the 'html' folder in your template directory (base_dir/templates/your_temp_name/html/com_k2 - if you wish, you can give a different name for your new k2 template). The file which you have to edit to set the desired description is category_item.php
Search for:
<?php if($this->item->params->get('catItemIntroText')): ?>
<!-- Item introtext -->
<div class="catItemIntroText">
<?php echo $this->item->introtext; ?>
</div>
<?php endif; ?>
and replace it with the code I gave before.


It did not work.

After replacing the codes, my site becomes completely blank.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 5 months ago #107915 by Krikor Boghossian
Replied by Krikor Boghossian on topic [SOLVED] How to limit item description characters?

I tried to change the parameters on K2 category setting. This works when click the category menu, but not work on homepage.

.

This setting only work when a menu item is pointing towards a single category and not multiple categories.
You can either manually specify an introtext for your items ( in my opinion this is the best option ) or,
you can select which tags to strip (globally) from the content tab on the component's configuration and use a simple PHP snippet like :
					
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