scriptygoddess

10 Feb, 2003

Scrolling Comments

Posted by: Jennifer In: Scripts

Promo asked for a script that would display comments on the main page, but in a scrolling box, so that if the comments ran long, they didn't make the page unbareably long (but still all visible on the one page). It was actually incredibly simple to do thanks to CSS. (He also only wanted it to display if there WERE comments to display (so you don't just have this empty box there for no reason…but that's actually a script I've posted here before – so here's the combination of them both)

<?
if (<$MTEntryCommentCount$> > 0) {
?>
<p>Comments: (total: <$MTEntryCommentCount$>)
<div style="background-color: #D4D4D4; height: 200; overflow: auto; padding: 5px;">
<MTEntryIfAllowComments>
<MTComments>
<p><$MTCommentBody$></p>
<p>Posted by: <$MTCommentAuthorLink spam_protect="1"$> on <$MTCommentDate$></p>
</MTComments>
</MTEntryIfAllowComments>
</div>
<?
}
?>

Copy, paste and use as is. Nothing more you need to do. :) (Unless you want to customize, of course).

21 Responses to "Scrolling Comments"

1 | Richard

February 10th, 2003 at 9:09 pm

Avatar

This will break W3C validation of your front page, because you cannot have more than one <div id="commentScrolls" [etc…]> per page.

An alternative approach might be to have <div id="commentScrolls_<$MTEntryID$> [etc…]>.

2 | Jennifer

February 10th, 2003 at 9:14 pm

Avatar

Actually – do you need the ID attribute in there at all to be w3c compliant? I removed it from the demo and it still works fine…

3 | Jason D-

February 10th, 2003 at 10:23 pm

Avatar

Doesn't really work in Safari. There are no scroll bars.

4 | Promo

February 10th, 2003 at 11:44 pm

Avatar

OK now lets add one more function….how about it only becomes a scroll box if the comment count is above a given number?

How would that look?

5 | Jennifer

February 11th, 2003 at 8:23 am

Avatar

Jason – yeah, unfortunately, as far as I can tell – that "overflow: scroll;" appears to be an IE only thing. :-\

6 | Jennifer

February 11th, 2003 at 8:30 am

Avatar

I take it back… I'm in NS 7 and the scrolly things work! WOO HOO! (more reasons for NS people to upgrade.)

7 | Richard

February 11th, 2003 at 12:32 pm

Avatar

Jennifer: You're right, you don't need the ID. I'm just saying if you had ID's, they'd have to be unique.

8 | Jennifer

February 11th, 2003 at 12:44 pm

Avatar

Ok, cool. Since it's not really needed, I'm going to update the post and take them out, and let people customize it as they need to. (ie. if they need to add IDs for whatever reason they can do so – but the default code won't be a problem)
Thanks!

9 | Jennifer

February 12th, 2003 at 9:38 pm

Avatar

Promo – Here you go:

<?
if (<$MTEntryCommentCount$> > 0) {
?>
<p class="footertext">Comments: (total: <$MTEntryCommentCount$>)
<div style="background-color: #D4D4D4; height: 200;
<?
if (<$MTEntryCommentCount$> > 3) {
?>
overflow: auto;
<? } ?>
padding: 5px;">
<MTEntryIfAllowComments>
<MTComments>
<p><$MTCommentBody$></p>
<p class="footertext">Posted by: <$MTCommentAuthorLink spam_protect="1"$> on <$MTCommentDate$></p>
</MTComments>
</MTEntryIfAllowComments>
</div>
<?
}
?>

That 3 – change that to whatever number of comments you want to display before you start adding scroll bars.

10 | Jennifer

February 12th, 2003 at 9:47 pm

Avatar

Sorry slight mis-wording there…
If the comments are LESS than 3 – it will not show the scroll bars…

11 | Charlie Lindahl

February 14th, 2003 at 3:29 pm

Avatar

Actually you *can* do conditional scrollbars
by using the

overflow: auto;

option.
This works in NS7, Mozilla, IE6 … haven't tried it on a Mac yet (with Safari or IE).

12 | Jennifer

February 15th, 2003 at 2:55 pm

Avatar

Yeah – that works better… I'll update the post. Thanks! :)

13 | JD

April 14th, 2003 at 9:14 pm

Avatar

I know this is old now…but I just tried implementing it.

Anywho…for some reason (of which I am sure there is one) the greater than is getting interpretted as a surrounding bracket.
Understand what I mean? You can see the effects on my main page.

Any help would be appreciated.

14 | Jennifer

April 14th, 2003 at 9:21 pm

Avatar

Your page is .html… did you set up your site to process .html pages like .php?

15 | JD

April 14th, 2003 at 9:40 pm

Avatar

Well, not that I know of….so that would probably be a no.

Sorry if you covered this in a post elsewhere, I don't want to be a pain in the neck.

16 | John Kranz

July 20th, 2003 at 4:06 pm

Avatar

My page is also .html. I got the same type of error. Are you saying PHP is required for this script to run? I don't see any PHP calls.

17 | JD

July 20th, 2003 at 4:28 pm

Avatar

Yep, I actually got mine to work…requires you to add the following line to your .htaccess file to correctly parse your html file…

AddType application/x-httpd-php .html .php .htm

Or change all your files to .php files

And it is the "&lt?" and "?&gt" that surround the PHP code fragments. In a .php file you don't need to say that it is php…it already gets parsed that way…

At least that is how I understand it.

18 | Maarten Legene

February 2nd, 2004 at 2:21 pm

Avatar

If I add the line below to my .htaccess, the server gives an internal error. Why that?

AddType application/x-httpd-php .html .php .htm

19 | Maarten Legene

February 2nd, 2004 at 3:54 pm

Avatar

OK, I renamed index.html into index.php and now it works. But….. still no any scrollbars afte three comments.
Please have a look at http://www.sos-papa.com/nieuws/nieuws1/index.php

You also will notice that all hyperlinks in blogbody and "posted by" stay yellow (= default), while I ordered blogbody to make these red. Blogbody is listening to the "hover" (red, bold) command but doesn't listen to the link command.

20 | Emmanuel's Professional Blog

February 13th, 2003 at 12:37 am

Avatar

Inlining Scrollable Comments
I have been interested in showing the comments on the main page for a very long time. Problem: they can

21 | Your Guess Is As Good As Mine

November 6th, 2003 at 6:01 pm

Avatar

How Very Odd
Changes made by editing post now fail to appear in the entry on the main page of the weblog, yet the entry in Individual Archives shows the changes.

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