scriptygoddess

11 Aug, 2002

selective showing/hiding comments

Posted by: Jennifer In: Scripts

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…)

8 Responses to "selective showing/hiding comments"

1 | Promo

August 12th, 2002 at 9:12 am

Avatar

Thank you Jenn! I can't wait to try this out, it sounds great. I'll let you know how it goes.

Thanks!

2 | Gaile

August 13th, 2002 at 2:01 pm

Avatar

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.

3 | Jennifer

August 13th, 2002 at 10:34 pm

Avatar

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.

4 | Promo

August 16th, 2002 at 5:17 pm

Avatar

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!

5 | Jennifer

August 16th, 2002 at 8:04 pm

Avatar

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…

6 | Promo

August 26th, 2002 at 9:36 am

Avatar

Worked like a charm, as always. Thanks so much!

7 | Milou

September 27th, 2002 at 7:28 am

Avatar

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.

8 | Anonymous

November 12th, 2002 at 9:54 pm

Avatar

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

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