ZenphotoCMS Forum
How to shrink album descriptions - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: How to shrink album descriptions (/thread-1115.html)

Pages: 1 2


How to shrink album descriptions - elderz - 2007-02-02

This might be a question for Chili-Frie as it's probably specific to the theme, but any ideas would be appreciated. I've had no trouble setting up ZP, but one thing that bothers me is that I cannot display only a partial description sometimes. If you look at one of my subalbums at http://www.kloofcycles.com/zen/index.php?album=Expedition you will see that some of the descriptions are pretty big. I like having that there when you are on the album page, but when you are just browsing through the albums, it would be nice if there was some way to truncate the amount of description showed (after 40 characters or something). This would keep the page to a more reasonable size and easier to view.

Thanks in advance for your help.




How to shrink album descriptions - Chilifrei64 - 2007-02-02

I am not sure there is a function for this yet in zenphoto. I will take a look and see what I can find but I am pretty sure you would have to write a custom function to attain this.




How to shrink album descriptions - elderz - 2007-02-02

If you have any hints on where to start with that, I'm more than willing to take a crack at it.




How to shrink album descriptions - trehug - 2007-02-15

maybe on the index page, you can wrap the description in a smaller container div, and set overflow to none.....just a thought. maybe put a "..." as a footer too.

haven't tried it, but it might work
/tre




How to shrink album descriptions - trisweb - 2007-02-15

There is a function, as a matter of fact, it's used in the comment display on the admin page. It's probably called truncate_something... I'll find it later if you can't.




How to shrink album descriptions - trehug - 2007-02-15

hi - i am not disagreeing - but i don't see that function anywhere? sorry for seeming to disagree with you

  • i did try changing the zen.css in the theme folder to set the class "albumdesc" to a specific height, and set overflow:hidden - and that worked, but, it's not elegant at all....bit brutal really - yet in a pinch, it works 4 me.

OTOH - am i missing a bunch of options in my admin page? my version was just installed last night (feb 14) so it must be up-to-date. ???

thanks for being so in touch, this is excellent, i do plan to support you guys in a real sense!
again, all the best /tre




How to shrink album descriptions - trehug - 2007-02-15

ok...i see the view truncated/full remark in the coments section, but i believe that i, and elderz were looking for something a bit different - so i submit this for everyones review:

in the /zen folder, edit the file: template-functions.php

find the function called printAlbumDesc

right below it, create a new function, as follows:

function printAlbumDescII($editable=false) {
global $_zp_current_album;
if ($editable && zp_loggedin()) {
echo "" . getAlbumDesc() . "\n";
echo "initEditableDesc('albumDescEditable');";
} else {
if(strlen(getAlbumDesc())>100) {
echo substr(getAlbumDesc(),0,100) . "...";
} else {
echo getAlbumDesc();
}
}
}

then - in your theme folder, edit the index.php file. where the line is:

relace with:

  • that's it, and it adds an elipses (...) to the end of the cutoff description. in my function above, you see the strlen is checking for strings over 100, otherwise print whole thing. if you want a different length as your cutoff - change in both places.

  • i guess to complete this - the cutoff length could be a global, and set it in your config file - but i just started all thi so didn't want to get too carried away.

hth, please let me know if this is not advisable, thanks
/trev




How to shrink album descriptions - trisweb - 2007-02-15

Looks good :-) Like I said though, there's already a function in ZP for that:

`function truncate_string($string, $length) {

if (strlen($string) > $length) {

$pos = strpos($string, " ", $length);

return substr($string, 0, $pos) . "...";

} else {

return $string;

}

}`

(You don't need to copy it anywhere, it's in functions.php already)

This one truncates a $string to $length, but only does it at word boundaries so things aren't unreadable. Just use it as truncate_string($description, 100);




How to shrink album descriptions - trehug - 2007-02-15

thanks - that is clearly the correct method and i need to study all the functions so i know whats there already

  • small issue however, in my test, it does not seem to work....

in my index.php file i have:

and in my functions.php i changed the function for testing, to this:

function truncate_string($string, $length) {
if (strlen($string) > $length) {
$pos = strpos($string, " ", $length);
return "test no" . substr($string, 0, $pos) . "...";
} else {
return "test yes" . $string ;
}
}

but it prints out the whole description, without truncating, and without pre-pending any text, so it seems like it is not getting called.
so sorry to carry this on one more level, but i'd love to get it right...do you have any advice why this behaves like this?
thanks again! /trev




How to shrink album descriptions - elderz - 2007-02-28

Hi guys. Thanks for all your help. I haven't actually taken a look at zp in a while as I've been busy with some other projects (you know how it is). Thanks for pointing out the existing function Tris. trehug is right in that we were trying to have the description only truncate on the album select page (index or subalbum page). For that, I just made a second function printAlbumDescSmall():

function printAlbumDescSmall($editable=false) {
global $_zp_current_album;
if ($editable && zp_loggedin()) {
echo "" . truncate_string(getAlbumDesc(),200) . "\n";
echo "initEditableDesc('albumDescEditable');";
} else {
echo truncate_string(getAlbumDesc(),200);
}
}

I then call that instead of printAlbumDesc() in index.php and in the subalbums portion of album.php. This worked great for me. Thanks again, both of you.

-Brendan




How to shrink album descriptions - tcserpa - 2007-05-17

I am using this (wonderful) technique to limit project descriptions, and now i have a question. Would it be possible to set a character, or other specific string as the truncate location? As in, rather than truncating at the 100th character it would truncate at the first instance of 'xxx'?

I have a feeling that this is more complicated than i am imagining.

Either way, good work on these functions.




How to shrink album descriptions - elderz - 2007-05-21

There are a couple different ways you can do this I think. First would be to alter the truncate_string function. You could do something like

`function truncate_string($string, $delimiter) {

$pos = strpos($string, $delimiter);

if ($pos === FALSE) return $string;

return substr($string, 0, $pos) . '...';

}`

Or you could edit the printAlbumDesc function (or make a new one)

`function printAlbumDesc($editable=false) {

global $_zp_current_album;

$pos = strpos(getAlbumDesc(), 'xxx')

if ($pos === FALSE) $pos = strlen(getAlbumDesc())

if ($editable && zp_loggedin()) {

echo "" . truncate_string(getAlbumDesc(),$pos) . "n";

echo "initEditableDesc('albumDescEditable');";

} else {

echo truncate_string(getAlbumDesc(),200);  

}

}`

I like the second method better because it doesn't tamper with truncate_string, which is probably used somewhere else. Alternately, you could make a whole new function, like I did and call it instead of printAlbumDesc. You might have to play around with the above script a little as I am not at home so I can't test this and I don't really know php syntax.




How to shrink album descriptions - bigdyce45 - 2007-11-16

elderz - For some reason, I can't get this to work. I'm a bit of a noob. I copied and pasted the function exactly as you have it into the template-functions.php and called it in the index.php with printAlbumDescSmall()

Any ideas?




How to shrink album descriptions - bigdyce45 - 2007-11-16

Never mind, I'm an idiot.




How to shrink album descriptions - elderz - 2007-11-16

You want to put it in album.php when you call that though you probably already figured that out. Don't worry, we've all done that (and will again).




How to shrink album descriptions - Barbara - 2007-11-24

I have a problem with this code.
Say the character limit is set to 100 and I want to add a hyperlink into the description.
If the link comes after the first 100 characters everything works great, otherwise it just breaks my html code.

Take this example:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut link
The first 100 characters are
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut tag is broken so the html becomesLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut




How to shrink album descriptions - elderz - 2007-11-28

There are generally two schools of thought on this. The first is that you enforce the character limit strictly and just strip tags from the content so it would come out as plain text, looking something like:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut link

You could do that by simply calling truncate_string(strip_tags(getAlbumDesc()),200).

I don't like this method and I'm assuming that's not what you want either. The other way to do it is to leave the html intact like you were showing above. Here is one way that should work, though it's pretty ugly. Normally, I wouldn't do something like this where it loops through everything, but your descriptions/char limit probably aren't that long anyway so it shouldn't really matter.

`function truncate_string_with_tags($string, $length) {

$pos=0;

$count=0;

$inc=true;

while(&#36;pos < &#36;length) {

    if(&#36;string[&#36;pos] == '') {

        &#36;inc=true;

    }

    if(&#36;inc) {

        &#36;pos++;

    }

}

while(&#36;count != 0) {

    if(&#36;string[&#36;pos] == '') {

        &#36;inc=true;

    }

    if(&#36;inc) {

        &#36;pos++;

    }

}

return substr(&#36;string, 0, &#36;pos) . '...';

}`

Then, just call truncate_string_with_tags() instead of truncate_string() in:

`function printAlbumDescSmall(&#36;editable=false) {

global &#36;_zp_current_album;

if (&#36;editable && zp_loggedin()) {

echo "" . truncate_string(getAlbumDesc(),200) . "n";

echo "initEditableDesc('albumDescEditable');";

} else {

echo truncate_string(getAlbumDesc(),200);

}

}`

I haven't tested this and I'm [b]sure[/b] there are better ways to do this, but it should at least preserve your links.




How to shrink album descriptions - Barbara - 2007-11-30

Thanks elderz. There's something that prevents the code from working though.
I pasted both functions in custom-functions.php and here's what it says when I load tha albums:

Fatal error: Maximum execution time of 60 seconds exceeded in C:\Documents and Settings\PERSONAL\Desktop\xampp\htdocs\zenphoto\themes\default\custom-functions.php on line 9

Line 9 is:
if(&#36;string[&#36;pos+1] == '/') {




How to shrink album descriptions - elderz - 2007-12-01

Edit: I overlooked a couple things. This one works for me:

`function truncate_string_with_tags(&#36;string, &#36;length) {

if(strlen(&#36;string) < &#36;length) {

return &#36;string;

}

&#36;pos=0;

&#36;charcount=0;

&#36;tagcount=0;

&#36;inc=true;

while(&#36;charcount < &#36;length) {

if(&#36;string[&#36;pos] == '') {

  &#36;inc=true;

}

if(&#36;inc) {

  &#36;charcount++;

}

&#36;pos++;

}

while(&#36;tagcount != 0 && &#36;pos < &#36;lenth) {

if(&#36;string[&#36;pos] == '') {

  &#36;inc=true;

}

if(&#36;inc) {

  &#36;pos++;

}

}

return substr(&#36;string, 0, &#36;pos) . '...';

}`




How to shrink album descriptions - Barbara - 2007-12-01

Works like a charm now. Thank you!