Hi,
I'm new here and a bit confused right now. I want to add the 3 latest comments to my gallery-indexpage. I found
http://www.zenphoto.org/trac/wiki/ZenphotoHacks#RecentCommentsCustomFunction but my php knowledge is limited and the FAQ didn't help much. In other words I have no clue how to add this function to my gallery. So can anyone point me in the right direction?
Thanks!
Comments
It is recommended that you put this code in a file called custom-functions.php and include it at the top of your theme files using this code: <?php require_once ('custom-functions.php'); ?>
What this will do is allow you to upgrade zenphoto without having to modify the zenphoto code every time you upgrade.
Can anyone take a look at it and fix it. Thanks in advance!
/* Show Latest Comments */
/* http://anton.gektoras.lt/2007/05/15/zenphoto-addons/ */
function my_truncate_string($string, $length) {
if (strlen($string)> $length) {
$short = substr($string, 0, $length);
return $short. '...';
} else {
return $string;
}
}
function printLatestComments($number) {
echo '<div id="showlatestcomments">';
echo '
';- <div class="commentmeta"><a href="';
';
';$comments = query_full_array("SELECT c.id, i.title, i.filename, a.folder, a.title AS albumtitle, c.name, c.website,"
. " c.date, c.comment FROM ".prefix('comments')." AS c, ".prefix('images')." AS i, ".prefix('albums')." AS a "
. " WHERE c.imageid = i.id AND i.albumid = a.id ORDER BY c.id DESC LIMIT $number");
foreach ($comments as $comment) {
$author = $comment['name'];
$album = $comment['folder'];
$image = $comment['filename'];
$albumtitle = $comment['albumtitle'];
if ($comment['title'] == "") {
$title = $image;
} else {
$title = $comment['title'];
}
$website = $comment['website'];
$comment = my_truncate_string($comment['comment'], 40);
$link = $author.' commented on '.$albumtitle.' / '.$title ;
$short_link = my_truncate_string($link, 40);
echo '
if (zp_conf('mod_rewrite') == false) {
echo WEBPATH.'/index.php?album='.urlencode($album).'&image='.urlencode($image).'/"';
} else {
echo WEBPATH.'/'.$album.'/'.$image.'" ';
}
echo 'title="'.$link.'">';
echo $short_link.':</div><div class="commentbody">'.$comment.'</div>
}
echo '
echo '</div>';
}
On the other hand, there is a function for this: `printLatestComments($number)` which you might rather use. It is part of template-functions.php.
We are hard at work and should shortly have an updated function guide posted on the zenphoto site.
It is still being worked on, but is pretty complete.