As this hack is
not working for me i tried something totally different.
I really was thinking why it is so hard to show comments on the front page.
I always use the comment option as a guestbook and wanted to show the latest comments in a box somewhere on a website.
So, why can i see comments in the 'guestbook' easily and is it so hard to create latest comments?
Like me there are many others who has problems with the hack in this tread.
So i used Darkslim's hack to show comments in the admin panel on my front-end.
So in my page i use this and it shows the 5 latest comments from one category. Though this is not for multiple categories:
- Code: Select all
<ul>
<?php
$commquery = $sql->select(array(
'table' => 'comments',
'orderby' => array('date', 'DESC'),
'limit' => array(0, $number ? $number : 5),
));
foreach($commquery as $row){
echo '<li><a id="truncateMe" href="http://www.domain.com/guestbook/">'.replace_comment('show', $row['comment']).'</a></li>';
}
?>
</ul>
This is working just great and straight out of the box.
When you want to truncate the comment, you could use this javascipt like i have and place it right after the above php code:
- Code: Select all
<script type="text/javascript">
var len = 32;
var a = document.getElementById('truncateMe');
if (a) {
var trunc = a.innerHTML;
if (trunc.length > len) {
/* Truncate the content of the 'a' , then go back to the end of the
previous word to ensure that we don't truncate in the middle of
a word */
trunc = trunc.substring(0, len);
/* Add an ellipses to the end and make it a link that expands
the paragraph back to its original size */
trunc += '...';
a.innerHTML = trunc;
}
}
</script>
This will truncate the comment after 32 characters.
If somebody make a modification of this, please post it here.
This is so much easier then the option which is given in this tread.
Hope somebody can use this.
The only problem i have is that i can't generate a link to the id of the comment it self.
So if anyone knows how to do that, my latest comments is just perfect for me.
D.