selective showing/hiding comments
Once again, Promoguy had a neat request for a script. Based on this script that shows/hides comments. (which is originally based on this script for showing hiding extended entries)
This script will let you selectively show the comments for ONE particular post “automatically”… that is, the default for the post(s) you select is SHOWING the comments. (and the rest will still default to hiding the comments)
Here is the revised script for the show/hide comments:
Somewhere in between the <head> and </head> of your html page, put this (if you’ve already installed the show/hide comments, then you probably already have this part done):
<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>
Put this line above your <$MTEntryBody$> tag:
<script language=”javascript”>
var openit = “false”;
</script>
paste this where you want your comments to go on the main index template (if you previously installed the show/hide comments, this goes IN PLACE of the old code you had)
<MTEntryIfAllowComments>
<script language=”javascript”>
if (openit == “true”) {
document.write(’<span id=”varP2<$MTEntryID$>” class=”extended” style=”display: none”>’);
} else {
document.write(’<span id=”varP2<$MTEntryID$>” class=”extended” >’);
}
</script>
<noscript>
<span id=”varP2<$MTEntryID$>” class=”extended”>
</noscript>
<a href=”<$MTEntryLink$>#<$MTEntryID pad=”1″$>” onclick=”showMoreComments(<$MTEntryID$>,’<$MTEntryLink$>#<$MTEntryID pad=”1″$>’);return false;”>show comments right here »</h4></a><br /></span>
<script language=”javascript”>
if (openit == “true”) {
document.write(’<div id=”varXYZ2<$MTEntryID$>”>’);
} else {
document.write(’<div id=”varXYZ2<$MTEntryID$>” style=”display: none”>’);
}
</script>
<noscript>
<div id=”varXYZ2<$MTEntryID$>” style=”display: none”>
</noscript>
<div style=”background-color: #D4D4D4; layer-background-color: #D4D4D4; border: 2px none #D4D4D4; padding-left: 10px; padding-right: 10px;”>
<h4 align=”right”>—————————————————————————<a href=”#<$MTEntryID pad=”1″$>” onclick=”showMoreComments(<$MTEntryID$>,0);return
true;”>« hide comments</a></h4>
<MTComments>
<$MTCommentBody$>
<h4>Posted by <$MTCommentAuthorLink$> at <$MTCommentDate$></h4><br /><br />
</MTComments>
<h4 align=”right”>—————————————————————————<a href=”#<$MTEntryID pad=”1″$>” onclick=”showMoreComments(<$MTEntryID$>,0);return
true;”>« hide comments</a></h4></div>
</div>
</MTEntryIfAllowComments>
THEN, In the post you want to have auto-show the comments, put this line somewhere in the actual TEXT of your post: (don’t worry, it shouldn’t show up):
<script language=”javascript”>var openit=”true”;</script>
The end. I only did a quick test on this, so if something acts funny let me know. (we’ll move any lengthy problems/discussions “off line” (ie. email) if there’s a lot of back and forth, and just come back with solutions, so fixes in the comments are easier to find…)
August 12th, 2002 at 9:12 am
Thank you Jenn! I can’t wait to try this out, it sounds great. I’ll let you know how it goes.
Thanks!
August 13th, 2002 at 2:01 pm
About the show/hide comments script - are any of you aware that Opera users aren’t able to view the comments when that script is used? I use it in my archives, and the exended entry show/hide bit on my main page, and only just found out that it doesn’t work in Opera 5 or 6.
I hate to stop using it, any ideas on why it won’t work there? Opera is becoming more and more popular, I don’t want to exclude those readers.
August 13th, 2002 at 10:34 pm
It is possible that it uses something in the Document Object Model that is not recongnized/supported by Opera. For example, Netscape has a more limited Document Object Model than Internet Explorer. Usually not too much you can do about it. Since I didn’t write the original script, and I’m not familiar with the Opera Document Object Model… not much I can offer. However, it is more like an “extra feature” that does not prohibit Opera users from viewing your site… so it’s your choice if you chose to remove it… but I wouldn’t think that it would restrict Opera users from using your site at all.. they just won’t get that particular bell/whistle.
August 16th, 2002 at 5:17 pm
Oh this just ROCKS! I love it, and it works great!!
Quick question: What would I need to add so that the “show comments right here ” would only display when I actually have comments.
As it is now, the “show comments right here” displays all the time.
No big deal though, I love the script regardless!
August 16th, 2002 at 8:04 pm
To only have it show when you have comments… above all the div’s for the script put this:
<?
if (<$MTEntryCommentCount$> > 0) {
?>
Then after all the show/hide comment stuff…
<? } ?>
Let me know if you need more explanation than that…
August 26th, 2002 at 9:36 am
Worked like a charm, as always. Thanks so much!
September 27th, 2002 at 7:28 am
Opera’s DOM doesn’t support changing display property using javascript, hence users won’t see anything (assuming the containers are initially display: none). You could try working around this with absolutely positioned divs, using visibility and z-index properties.
November 12th, 2002 at 9:54 pm
How do you make it so i remain on this page when I comment instead of going to the
mt-comments.cgi?entry_id=
page