4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: TerraZone on October 02, 2009, 02:25:18 PM
-
Hey there,
is it possible to "cut" the category-description in the category overview, after a few words?
I have some really long descriptions that won't fit into my list.
So it would be great if just the beginning is shown and the rest be replaced by ". . . " or something like that.
Any idea of how to do this?
-
Give this a try, it is untested
In /includes/functions.php
Find:
"cat_description" => format_text($cat_cache[$category_id]['cat_description'], 1),
After add:
"cat_description_short" => (strlen($cat_cache[$category_id]['cat_description']) > 20) ? Cut_String($cat_cache[$category_id]['cat_description'], 20)."..." : $cat_cache[$category_id]['cat_description'],
***In the above code the 20 represents the max length of description in characters, you can change this (twice) to fit your need ***
Above:
?>
Add:
function Cut_String($string, $max_length){
if (strlen($string) > $max_length){
$string = substr($string, 0, $max_length);
$pos = strrpos($string, " ");
if($pos === false) {
return substr($string, 0, $max_length)."...";
}
return substr($string, 0, $pos)."...";
}else{
return $string;
}
}
In your category_bit.html
Find:
{cat_description}
Replace with:
{cat_description_short}
-
thanks for your help, but there seem to be a bug in your code. after changing everything, the description for the first category ist displayed for EVERY category. But it IS cut ;)
-
"cat_description_short" => Cut_String($cat_cache[$category_id]['cat_description'], 20),
should do it.
-
Sorry about that, forgot to change that.
My post above is updated
-
@impss:
(strlen($cat_cache[$category_id]['cat_description']) > 20)
is not needed, as it's already implemented into the new function ;)
-
hi
how do {image_name_short} ?
which change code?
-
category_bit.html
-
image name: this picture in istanbul
image_name_shor: this picture
how do :)
-
Oh, completely misunderstood your question. Sorry.
Same deal, in includes/functions.php find:
"image_name" => format_text($image_row['image_name'], 2),
insert below:
"image_name_short" => Cut_string(format_text($image_row['image_name'], 2), 20),
[EDIT]
Just found a nice code snippet that should only count and cut text, disregarding HTML tags, and supposedly should not break HTML in the text either:
http://www.gsdesign.ro/blog/cut-html-string-without-breaking-the-tags/
-
Warning: Missing argument 2 for Cut_String(), called in C:\wamp\www\includes\functions.php on line 454 and defined in C:\wamp\www\includes\functions.php on line 1811
Warning: Missing argument 2 for Cut_String(), called in C:\wamp\www\includes\functions.php on line 454 and defined in C:\wamp\www\includes\functions.php on line 1811
Warning: Missing argument 2 for Cut_String(), called in C:\wamp\www\includes\functions.php on line 454 and defined in C:\wamp\www\includes\functions.php on line 1811
Warning: Missing argument 2 for Cut_String(), called in C:\wamp\www\includes\functions.php on line 454 and defined in C:\wamp\www\includes\functions.php on line 1811
in 454 line: "image_name_short" => Cut_string(format_text($image_row['image_name'], 2)),
in 1811 line: function Cut_String($string, $max_length){ if (strlen($string) > $max_length){
$string = substr($string, 0, $max_length);
$pos = strrpos($string, " ");
if($pos === false) {
return substr($string, 0, $max_length)."...";
}
return substr($string, 0, $pos)."...";
}else{
return $string;
}
}
-
too early for me :oops:...code fixed.
-
V@no,
Can this also be done for image description?
Thanks!