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

21 Responses to “Scrolling Comments”

  1. Richard Says:

    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 Says:

    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- Says:

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

  4. Promo Says:

    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 Says:

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

  6. Jennifer Says:

    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 Says:

    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 Says:

    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 Says:

    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 Says:

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

  11. Emmanuel's Professional Blog Says:
    Inlining Scrollable Comments
    I have been interested in showing the comments on the main page for a very long time. Problem: they can

  12. Charlie Lindahl Says:

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

  13. Jennifer Says:

    Yeah - that works better… I’ll update the post. Thanks! :)

  14. JD Says:

    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.

  15. Jennifer Says:

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

  16. JD Says:

    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.

  17. John Kranz Says:

    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.

  18. JD Says:

    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.

  19. Your Guess Is As Good As Mine Says:
    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.

  20. Maarten Legene Says:

    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

  21. Maarten Legene Says:

    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.