Scrolling Comments
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).
February 10th, 2003 at 9:09 pm
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...]>.
February 10th, 2003 at 9:14 pm
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…
February 10th, 2003 at 10:23 pm
Doesn’t really work in Safari. There are no scroll bars.
February 10th, 2003 at 11:44 pm
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?
February 11th, 2003 at 8:23 am
Jason - yeah, unfortunately, as far as I can tell - that “overflow: scroll;” appears to be an IE only thing. :-\
February 11th, 2003 at 8:30 am
I take it back… I’m in NS 7 and the scrolly things work! WOO HOO! (more reasons for NS people to upgrade.)
February 11th, 2003 at 12:32 pm
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.
February 11th, 2003 at 12:44 pm
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!
February 12th, 2003 at 9:38 pm
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.
February 12th, 2003 at 9:47 pm
Sorry slight mis-wording there…
If the comments are LESS than 3 - it will not show the scroll bars…
February 13th, 2003 at 12:37 am
I have been interested in showing the comments on the main page for a very long time. Problem: they can
February 14th, 2003 at 3:29 pm
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).
February 15th, 2003 at 2:55 pm
Yeah - that works better… I’ll update the post. Thanks!
April 14th, 2003 at 9:14 pm
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.
April 14th, 2003 at 9:21 pm
Your page is .html… did you set up your site to process .html pages like .php?
April 14th, 2003 at 9:40 pm
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.
July 20th, 2003 at 4:06 pm
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.
July 20th, 2003 at 4:28 pm
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 “<?” and “?>” 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.
November 6th, 2003 at 6:01 pm
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.
February 2nd, 2004 at 2:21 pm
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
February 2nd, 2004 at 3:54 pm
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.