scriptygoddess

29 Mar, 2003

show more of this comment…

Posted by: Jennifer In: Scripts

So you've got a few people who like to leave really long comments on your blog. It's all well and good, but it's making your page run really long, and some people just don't want to scroll through all that just to get to the next comment.

This script will let you (after a certain point) put a "show more of this comment" link. (While the show/hide script is javascript – there's some php in there to show the "show/hide" link only when the comment reaches your "max"

If you already have the functions installed from this script, then skip this step. Otherwise, put this in between your <head> </head> tags.

<script language="Javascript">
<!–
function showMoreComments(varA12, varB12){
var1232 = ('varXYZ2' + (varA12));
varABC2 = ('varP2' + (varA12));
if( document.getElementById ) {
if( document.getElementById(var1232).style.display ) {
if( varB12 != 0 ) {
document.getElementById(var1232).style.display = "block";
document.getElementById(varABC2).style.display = "none";
} else { document.getElementById(var1232).style.display = "none";
document.getElementById(varABC2).style.display = "block"; }
} else { location.href = varB12;
return true; }
} else { location.href = varB12;
return true; }
}
//–>
</script>

Then this part completely replaces your existing MTComments section. (It'll even work INSIDE a "show/hide comments" block already on the page – so it's a show/hide, inside a show/hide)

<MTComments>
<?
if (strlen("<$MTCommentBody encode_php="qq"$>") > 100) {
?>
<span id="varP2<$MTCommentID$>">
<$MTCommentBody trim_to="100"$>
<p><a href="<$MTEntryLink$>#<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTCommentID$>,'<$MTEntryLink$>#<$MTEntryID pad="1"$>');return false;">
show the rest of the comment »
</a></p></span>
<div id="varXYZ2<$MTCommentID$>" style="display: none">
<$MTCommentBody$>
<p><a href="#<$MTCommentID pad="1"$>" onclick="showMoreComments(<$MTCommentID$>,0);return true;">
« hide rest of comment
</a></p></div>
<?
} else {
?>
<$MTCommentBody$>
<? } ?>
<p>Posted by <$MTCommentAuthorLink show_email="0"$> at <$MTCommentDate$></p><br /><br />
</MTComments>

Change the text as you want, and the number where you want to cut the comment off. (That 100 represents the number of characters. ie. letters, spaces, etc.)

4 Responses to "show more of this comment…"

1 | Kevin

March 29th, 2003 at 11:27 pm

Avatar

Perfect solution! Although –deep down– I'm sorta thinking that I might be responsible for this somehow.

2 | hmw

March 30th, 2003 at 8:27 am

Avatar

Jenn, I can't thank you enough!! This is perfect – I can't wait to install it 😉

3 | Doc

March 30th, 2003 at 11:09 am

Avatar

I get an error:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /index.php on line 1018

the code for that section is below. I believe I am getting php conflicts?

<!– Show Comments –>
<MTEntryIfAllowComments>
<span id="varP2<$MTEntryID$>" class="extended"><a href="<$MTEntryLink$>#<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTEntryID$>,'<$MTEntryLink$>#<$MTEntryID pad="1"$>');return false;">
<SCRIPT><!– BEGIN EMBEDDED COMMENT COUNT SCRIPT –>
if(<$MTEntryCommentCount$>==0) {
document.write('No Comments')
} else {
if (<$MTEntryCommentCount$>==1) {
document.write('Show Comment »')
} else {
if (<$MTEntryCommentCount$>==2) {
document.write('Show Both Comments »')
} else {
document.write('Show All <$MTEntryCommentCount$> Comments »')
}

}
}
</SCRIPT><!– END EMBEDDED COMMENT COUNT SCRIPT –>
</a><br /></span><div id="varXYZ2<$MTEntryID$>" style="display: none">
<div style="border-top:1px solid #666666; margin-top:5px;">

<MTComments sort_order="ascend">
<div style="border-bottom:1px dashed #666666;">
<?
if (strlen("<$MTCommentBody encode_php="qq"$>") > 100) {
?>
<span id="varP2<$MTCommentID$>">
<$MTCommentBody trim_to="100"$>
<p><a href="<$MTEntryLink$>#<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTCommentID$>,'<$MTEntryLink$>#<$MTEntryID pad="1"$>');return false;">
Show More »
</a></p></span>
<div id="varXYZ2<$MTCommentID$>" style="display: none">
<$MTCommentBody$>
<p><a href="#<$MTCommentID pad="1"$>" onclick="showMoreComments(<$MTCommentID$>,0);return true;">
« Show Less
</a></p></div>
<?
} else {
?>
<$MTCommentBody$>
<? } ?>
<p>Posted by <$MTCommentAuthorLink spam_protect="1" show_email="0"$> at <$MTCommentDate$></p></div>
</MTComments>

</div>
<a href="#<$MTEntryID pad="1"$>" onclick="showMoreComments(<$MTEntryID$>,0);return
true;">
<SCRIPT><!– BEGIN EMBEDDED COMMENT COUNT SCRIPT –>
if(<$MTEntryCommentCount$>==0) {
document.write('« No Comments Here Either')
} else {
if (<$MTEntryCommentCount$>==1) {
document.write('« Hide Comment')
} else {
document.write('« Hide Comments')
}
}
</SCRIPT><!– END EMBEDDED COMMENT COUNT SCRIPT –>
</a></div>
</MTEntryIfAllowComments>

4 | Jennifer

March 31st, 2003 at 10:20 pm

Avatar

FYI – in case you're wondering – I'm working with Doc "offline" but I think it has to do with a problem in his MT install… I have this script up and running just fine.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements