![]() |
|
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 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
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! 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) { then - in your theme folder, edit the index.php file. where the line is: relace with:
hth, please let me know if this is not advisable, thanks 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) {
} else {
} }` (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 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
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) { but it prints out the whole description, without truncating, and without pre-pending any text, so it seems like it is not getting called. 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) { 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()) {
} else {
} }` 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. Take this example: 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:
You could do that by simply calling 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) {
}` Then, just call truncate_string_with_tags() instead of truncate_string() in: `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 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. 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: 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($string, $length) { if(strlen($string) < $length) {
} $pos=0; $charcount=0; $tagcount=0; $inc=true; while($charcount < $length) {
} while($tagcount != 0 && $pos < $lenth) {
} return substr($string, 0, $pos) . '...'; }` How to shrink album descriptions - Barbara - 2007-12-01 Works like a charm now. Thank you! |