Forums

[resolved] How to display 3 most recent comments to my front page (10 posts)

  1. Matt
    Member
    Posted 2 years ago #

    Hey guys,

    I'm going crazy here and can't figure out what i'm doing wrong... here is my code. Any help would much appreciated.

    <?php if (is_front_page()) {?>
     <div id="socialTabs-1">
                    	<ol class="commentlist">
    						<?php wp_list_comments(); ?>
                        </ol>
                    </div>
    <?php }?>
  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You could add a widget-capable area to index.php and then make use of the Recent Comments widget.

  3. Matt
    Member
    Posted 2 years ago #

    Is there any other way?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Use wp_list_comments with a custom callback function? I still think the widget route is far easier.

  5. Matt
    Member
    Posted 2 years ago #

    I'm not getting anything back from the callback approach. I took the code right out of the example.

  6. Matt
    Member
    Posted 2 years ago #

    Could it be something with my theme? or the syntax?

  7. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Actually I'm not convinced that wp_list_comments will work, thinking about it further. get_comments might...

  8. Matt
    Member
    Posted 2 years ago #

    ooo okay i will try this...

  9. Matt
    Member
    Posted 2 years ago #

    okay it's working now... nice.

    One last question to ask:

    If i want to format the time

    <?php
    					$comments = get_comments();
    					  foreach($comments as $comm) :
    						echo "<h3 class=\"commentHeader\">".($comm->comment_author)."&nbsp;- &nbsp;".($comm->comment_date)."</h3>";
    						echo "<p class=\"commentPara\">".($comm->comment_content)."</p>";
    						echo "<hr>"."<br />";
    					  endforeach;
    					?>

    How can I do that to make it look like this for this piece of code

    Friday, September 24, 2004

  10. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try using:

    echo '<h3 class="commentHeade">'. $comm->comment_author .'&nbsp;- &nbsp;'.date('l, F j, Y', $comm->comment_date).'</h3>';

    http://uk2.php.net/manual/en/function.date.php

Topic Closed

This topic has been closed to new replies.

About this Topic