scriptygoddess

06 Jun, 2004

Show/Hide Comments in WordPress II – wp-dropdown-comments.php

Posted by: Jennifer In: WordPress|WordPress Hacks

In the interest of making things simpler – I created a special version of the wp comments page that you can just upload and be done with it.

So:
1) you need the show/hide more plugin installed. (if it isn't already)

2) Download this file, save it as "wp-dropdown-comments.php" into your wordpress install directory.

3) add the following line to your index.php where you want your dropdown comments to display:

<?php include(ABSPATH . 'wp-dropdown-comments.php'); ?>

Note: that line does NOT!! replace your wp-comments.php line.

An additional note I'll make here and on the show/hide more (post) version:
Make sure you have the following in your template! (It's in the original WP index.php template, but if you're creating your own, you may have easily forgotten to include it) :

<?php wp_head(); ?>

That line would go in between your <HEAD> </HEAD> tags.

Please post any problems/bugs in the comments. I've tested it on a test blog, but not extensively.

FYI – I recently made a change to the "show/hide more" plugin so it will automatically do the show/hide more on your posts without your needing to change your template – but if you wanted to keep your more links the way they were (because you only wanted to use the plugin for drop-down comments) – comment out this line in the plugin: add_action('the_content', 'the_contentshowhide'); by putting two slashes // in front of it.

49 Responses to "Show/Hide Comments in WordPress II – wp-dropdown-comments.php"

1 | Gina Divina :: Grr!

June 7th, 2004 at 2:19 pm

Avatar

[…] Blogged under: WordPress — Gina @ 10:19 am

I've been waiting for the show/hide expandable comments plugin to come out and it fina […]

2 | I am me » Dropdown comments

June 7th, 2004 at 7:20 pm

Avatar

[…] Web Design Tests — moisie @ 8:20 pm

I have been tinkering around with the show/hide expandable comments plugin […]

3 | yup-yup.com

June 8th, 2004 at 11:24 am

Avatar

[…] again, absolutely made my day. Want to show/hide comments right on your main page? Well, head on over here and pick it up. It's wond […]

4 | tormodh's journal » Shy Comments

June 8th, 2004 at 12:29 pm

Avatar

[…] This hack displays "comments" in the same manner, and only require one file apart to be copied […]

5 | Henna blogs ... » Installed some new plugins…

August 1st, 2004 at 7:48 pm

Avatar

[…] licking on them and so can you in the comments section… Apart from that I also added Show/Hide comments Plugin So the comments can now be viewed […]

6 | wurch.log » ausklappbare Kommentare

August 15th, 2004 at 11:30 am

Avatar

[…] r auf den Gedanken kommen sollte, Kommentare auf der Titelseite zu zeigen, könnte der Show/Hide Comments in WordPress II – wp-dropdown-comments.php

7 | scriptygoddess

September 5th, 2004 at 2:18 am

Avatar

[…] n't post this already (maybe I did and I just can't find it) – but on another blog, I have drop down comments set so it only does this for the first 'x […]

8 | Jen

June 6th, 2004 at 11:41 pm

Avatar

OMG Jenn, you're awesome!! I still hadn't been able to get Mark's version to work correctly. He was in the process of helping me, but he's out of town and so hadn't gotten back to me yet.

This version works perfectly and involves a lot less tweaking. Great job!! :)

9 | Tek

June 7th, 2004 at 12:19 am

Avatar

Wow!

Coooooolies! Thank you muchly! Works like a charm and so easy too! =)

10 | G'Day Mate - Reviews!

June 7th, 2004 at 8:59 am

Avatar

Blog Roundup (Sort of)
I don't have a full roundup for this week due to the transition of the main blog from MT to WP. I have yet to find out what the official Munuvian stance will be and I also failed to get…

11 | Sara

June 7th, 2004 at 9:18 am

Avatar

You are the best! I have to tell you that I didn't want to attempt the other version as it was too complicated for me to wrap my brain around the other day. :) This one works perfectly!! THANK YOU!!

12 | Charlene

June 7th, 2004 at 9:42 am

Avatar

clapping hands in glee!! Thank you.

13 | Gina

June 7th, 2004 at 10:01 am

Avatar

Thank you, Jennifer! :)

14 | Smells Like Fish, Tastes Like Chicken

June 7th, 2004 at 1:08 pm

Avatar

WordPressed!
So depending on if you are on LiveJournal or on my website, you will noticed that the site looks different. That is because finally, after many hours, both enjoyable and frustrating, I have finally made "the switch". Welcome to the new WP site. S…

15 | i am me

June 7th, 2004 at 2:21 pm

Avatar

Dropdown comments
I have been tinkering around with the show/hide expandable comments plugin and have integrated in with my custom fields plugin (the_meta_ii) So I can now specify on a per post basis to have dropdown commets or not.

The rest of the plugin is nowhere…

16 | kyramas

June 7th, 2004 at 2:46 pm

Avatar

I think the WP community is lucky to have you onboard !
Thanks for the great plugins !
Working like a charm.
cheers!

17 | Stacey

June 8th, 2004 at 2:40 pm

Avatar

Thanks Jennifer!

18 | kyramas

June 8th, 2004 at 3:15 pm

Avatar

Too bad it doesnt validate… :(
The part that doesnt is the ol id="commentlist" which repeats for each comment but being a unique id its an error in XTML 1.0 trans.
check it here : http://validator.w3.org/check?uri=http%3A%2F%2Fwww.kyramarios.gr%2Fdiary%2F&charset=%28detect+automatically%29&doctype=%28detect+automatically%29&ss=1

19 | Root

June 8th, 2004 at 6:13 pm

Avatar

Presumably if that id was a class it would be fine. Scriptygoddess I have only just found you. Wow. This is really neat. Tx.

20 | kyramas

June 8th, 2004 at 6:20 pm

Avatar

Yes it validates. But it breaks the CSS and you need to add some extra ".commentlist" classes. Other than that its ok !
Thanks Jennifer.

21 | Jennifer

June 8th, 2004 at 6:20 pm

Avatar

Yeah – if someone could test that out for me to make sure it doesn't screw anything up but does validate – let me know, and I'll update the file. :)

22 | Jennifer

June 8th, 2004 at 6:53 pm

Avatar

Cool. It's updated. We could also leave it with an id and have them each be unique by adding the post id. I'm not sure which is more important – unique id's or being able to stylize the class… either way – it's easily something you can edit on your own end. :)

23 | Shelby

June 13th, 2004 at 10:23 am

Avatar

Actually, kyramas, the reason that it won't validate is not because of the OL, it's because you're putting an OL inside a "span" – which is not acceptable via the XHTML standards.

In wp-dropdown-comments change every instance of span to div – making sure you include the end tags, and it will validate perfectly. :) Just so you know.

24 | Shelby

June 13th, 2004 at 10:28 am

Avatar

My apologies for posting again so soon:

I do realize that this means you couldn't necessarily put your hide/show comments "link" on the same line as anything else, and for some people, I can see where that would be a problem.

However, if it's important to you that your document validates, you can't put an OL inside a span. One other option is to use another method to format the comment output, which doesn't put any block-level elements (ol, ul, div, p…etc) inside an inline element (i.e., span)

25 | Greg

June 20th, 2004 at 2:42 am

Avatar

Sorry to post this here… but I'd like to know how you are able to list the trackbacks separately from the comments… right now they are all posting together and I like your format better. So far the WP forums have been no help at all. I'd appreciate any help or direction you can give.

26 | WxGal's World :: Journal

June 21st, 2004 at 10:24 pm

Avatar

Change is here
Or at least, it soon will be. I have decided that I AM going to switch my blog to WordPress….

27 | WxGal's World :: Journal

June 22nd, 2004 at 11:31 am

Avatar

Change is here
Or at least, it soon will be. I have decided that I AM going to switch my blog to WordPress….

28 | Mama Write

July 7th, 2004 at 8:01 pm

Avatar

Various WordPress Links
Rather than ping ScriptyGoddess multiple times and clog my sideblog with even more WordPress links, I decided to plop 'em all here. I'm going to give WordPress a try again on my course website, since there are various hacks that…

29 | alicson

July 12th, 2004 at 1:40 am

Avatar

hi.. i'm trying my hand at wordpress..your show/hide comments script works well, thank you. i'm wondering, though, if you/someone might know a way to have that "show comments" text show up only on the permalinked page, rather than the main page..
also, how to otherwise have the comments show up separately/away from where the "comments (#)" link is. that's the main thing i'm trying to accomplish, as i would like that link right below the affiliated post, but when it's clicked on and the page unrolls to allow for comments, it tears apart that piece of the page, to fit that all in.
(i initially asked this in the forums, which thus far has led me here..)

i would sincerely appreciate any suggestions..

30 | Sumaira

July 12th, 2004 at 10:31 pm

Avatar

Hi Jennifer – Love your site..wondering if you had any input im having with your show hide comments script. its only showing up on some of my posts, not all of them. Thoughts?

31 | rob

July 14th, 2004 at 5:03 pm

Avatar

Alicson: To only do something on a permalinked page, you can do this.

if($single) {
// page is permalinked
} else {
// page isn't permalinked
}

So in this instance:

< ?php if($single) { include(ABSPATH . 'wp-dropdown-comments.php'); } ?>

32 | Alicson

July 14th, 2004 at 9:34 pm

Avatar

Rob, thank you very much for that explanation.. i'll be playing with that.. thanks!

33 | Joelle

July 16th, 2004 at 4:37 pm

Avatar

Alas, it works for me not. Maybe I'm just totally impaired, but I get it to show up, but when I click it, it just takes me to the individual entry where it goes anyway when there are comments. It's not my site, it's here:

http://www.best-of-intentions.com

thoughts? The tag is in my header, the plug-ins were uploaded. I didn't replace anything, I just added that line, but sadly, it no worky.

34 | Joelle

July 16th, 2004 at 5:08 pm

Avatar

Ok, I was missing some javascript somewhere, but now it's working.

Thank you!

35 | Iva

September 4th, 2004 at 6:56 pm

Avatar

I was trying to do this myself (make the drop-down comments appear on the permanent link page only), but no success. All I get is parse errors. Can anyone help me? I want to have the drop-down comments on the permalink page only and a link to the permalink pages on category/archives/main.

36 | Jennifer

September 4th, 2004 at 10:07 pm

Avatar

Iva – to get this to work on individual archive pages, do the following:

1) comment out line 9 which looks like this:
if (!($single)) {
(just add two slashes in front of it so it looks like this:
// if (!($single)) {

2) Then comment out the very last } on the file (line 45) (yeah, it says "if you delete this the sky will fall on your head" but don't believe everything you read) 😉

37 | Jennifer

September 4th, 2004 at 10:19 pm

Avatar

FYI – to anyone interested – if you want to limit how many posts get drop down comments on it – see this post

38 | Iva

September 5th, 2004 at 5:49 am

Avatar

Thanks:)

That's what I've done, now there's just a link to comments on category/main/archive pages but…when I open the permalink page the comments are always open. The open/close doesn't work:(

I'm sorry if I'm giving you problems.

39 | Poonam

September 23rd, 2004 at 8:29 pm

Avatar

Jennifer,

How would you change the colors of the actual text from black to another color? I actually have it setup where it says:

Jennifer replies: and then the comment and I would like to change the colors of Jennier replies:

Any idea? I tried HTML code (/font) but did not work

40 | Monty

September 28th, 2004 at 6:37 pm

Avatar

Jenn,

If you notice comments #13 and #14, both of them are by Shelby, but on #13, the image "Subscribed" is displayed and on #14 it is not. I assume she hasnt changed her email address on #14. I have the same issue on my blog. Is this a bug?

41 | Jennifer

September 28th, 2004 at 8:45 pm

Avatar

Monty – this was basically fixed in the latest version of the wp subscribe to comments plugin – however older comments won't see the update/fix until the commenter leaves another comment on that same post.

42 | Wilhelm

October 22nd, 2004 at 6:29 am

Avatar

hello, Parse error: parse error, unexpected '}' in /srv/www/htdocs/wp-dropdown-comments.php on line 11, any ideas?

does it matter where i place the " < ?php include(ABSPATH . 'wp-dropdown-comments.php'); ?> on the index file ?. i place right under the other wp-comments's include …

43 | mel

November 1st, 2004 at 12:48 pm

Avatar

I'm so excited about getting the show more on the individual entry page. :) (re: comment #23)

Now, does anyone know if there is a way to get the comment-popups on the indiv. entry page too?

thanks!

44 | ryan masuga

December 14th, 2004 at 9:22 pm

Avatar

Hi – I'm using the dropdown menus on my site and everything is working just fine except for one minor thing in Firefox. If someone clicks a link that says, for example, "Show 5 Comments" they are "stuck" on that link. The user then has to click off the link to be able to scroll to read all the comments. This doesn't occur in other browsers, such as Safari. It's not a deal-breaker, but most of my visitors use Firefox. I thought it might have to do with possibly adding a "return false" in the JavaScript, but that's already in there. Is there a documented (or simple) fix for this? Thanks, and keep up the good scripting work.

45 | ryan masuga

December 17th, 2004 at 9:24 pm

Avatar

To answer my own question, I added 'this.blur();' right before the 'return false;' in the dropdown link and the problem of the link 'sticking' in Firefox no longer occurs.

46 | Ozguru

February 20th, 2005 at 6:02 am

Avatar

These instructions don't appear to work with 1.5 (because the code has changed so much). Is there a variation or a walk through for 1.5?

Thanks.

47 | Daisyhead

April 23rd, 2005 at 1:57 pm

Avatar

I couldn't get it to work with WP 1.5 either. Too bad. So far I don't see any other plugins that can do this. :-(

48 | ryan masuga

April 29th, 2005 at 8:10 am

Avatar

I just upgraded to 1.5 last night and have also founfd that the dropdown comments aren't working. So I too am jumping on the "can we get this to work with 1.5" bandwagon – would someone more versed in PHP look at solving this one? Thanks!

49 | scriptygoddess » Blog Archive » Show Hide “more” with WordPress

May 20th, 2008 at 11:47 am

Avatar

[…] If you'd also like to do show/hide comments: see this post for ideas on how to edit your wp-comments and/or this post for a seperate file you can upload and use (wp-dropdown-comments.php) […]

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