Results 1 to 2 of 2

Thread: Recent comments in two columns!

  1. #1
    hsmarginal is offline Hello World
    Join Date
    Oct 2011
    Posts
    3

    Default Recent comments in two columns!

    Hey there people!
    I've been stuck with a specific issue for a while now and have not been able to solve this. Hopefully you guys will be able to help me out with this.

    I've got a "Recent comments" tab on my blog; once clicked it opens up a list with the most recent comments with excerpts and then a link to the corresponding post title. It works fine so far, and everything shows up in the jquery tab fine.
    Below is a screenshot of this:
    recentposts.JPG

    And this is the simple code to get this:
    Code:
        <?php $comments = get_comments('status=approve&number=5'); ?>        <ul class="recomm">
            <?php foreach ($comments as $comment) { ?>
               <li class="recomm-wrapper"><?php
                   $title = get_the_title($comment->comment_post_ID);
                echo get_avatar( $comment, '53' );
                echo '<span class="recommauth">' . ($comment->comment_author) . '</span>';
                ?> said: "<?php
                echo wp_html_excerpt( $comment->comment_content, 300 ); ?>.."
                on <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"
                  rel="external nofollow" title="<?php echo $title; ?>">
                   <?php echo $title; ?> </a>
                </li>
            <?php }  ?> 
            </ul>
    What i want to do is to be able to have more comments showing up on this list without forcing the tab content table having to go further down. The idea is to have the comments stacking in two columns within instead and maybe even possibly numbering them. Something like this:

    1. Comment 6. Comment
    2. Comment 7. Comment
    3. Comment 8. Comment
    4. Comment 9. Comment
    5. Comment 10. Comment

    Would this be possible with the code i have? And how would i get on to do this? I am not great with codes and can simply follow guides and replace codes.

    Also, is there a way to make the corresponding post title link for each comment to appear in a new line rather than on the same line as the actual comment excerpt?

    At the moment what i have is:
    Author



    said: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod blandit nibh non tristique. In ac quam a nunc rhoncus molestie. Aliquam dignissim vestibulum suscipit. Quisque gravida, neque a pretium blandit, nisi felis laoreet massa, quis .." on My necklace gave her custom eyes.

    I want it to be like this:
    Author



    said: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod blandit nibh non tristique. In ac quam a nunc rhoncus molestie. Aliquam dignissim vestibulum suscipit. Quisque gravida, neque a pretium blandit, nisi felis laoreet massa, quis .." on
    My necklace gave her custom eyes.


    Thank you !
    G

  2. #2
    jeffrose is offline Hello World
    Join Date
    Aug 2010
    Location
    Vancouver, Canada
    Posts
    3

    Default

    Putting the Post title on the next line is just a matter of inserting a <br /> between "on" and the "<a" that starts the link. For example:
    Code:
    echo wp_html_excerpt( $comment->comment_content, 300 ); ?>.." <br />
    on <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"
    rel="external nofollow" title="<?php echo $title; ?>">
     <?php echo $title; ?> </a>
    will produce "on POST TITLE" on a line of it's own.

    You should be able to change the loop to output 2 sets of comments. The first line says "Number = 5" which you would want to increase to 10 (or whatever). Then the next section that creates the UL group would be repeated. As long as you always have 10 comments change the foreach loop into 2 counters of 0 to 4 and wrap each in a div. You may need to experiment with floats, but here's the concept:

    This code won't work, as I've mixed up the $comments object and an array (2am), but the concept is there.

    Code:
    <?php $comments = get_comments('status=approve&number=10'); ?>
        <ul class="recomm" style='float:left;'>
            <?php show_comments( $comments, 0, 4 );
        </ul>
        <ul class="recomm" style='float:right;'>
            <?php show_comments( $comments, 5, 9 );
        </ul>
    <?php    
        function show_comments( $comments, $start, $end ){
            for ( $i = $start; $i <= $end; $i++ ){
                echo '<li class="recomm-wrapper">';
                
                $title = get_the_title($comment->comment_post_ID);
                echo get_avatar( $comment, '53' );
                echo '<span class="recommauth">' . ($comment->comment_author) . '</span>';
                echo ' said: ';
                echo wp_html_excerpt( $comment->comment_content, 300 );
                echo '...<br />';
                echo 'on <a href="' . get_permalink($comment->comment_post_ID) . '" rel="external nofollow" title='. $title . '">";
                echo $title . '</a>';
                echo '</li>';
            }
        }
    ?>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •