• Resolved kevin heath

    (@ypraise)


    Hi

    I’m currently developing a more useful author.php page using the Domtabs javascript to provide three tabbed sections – author bio, latest blogs and latest comments for each author.

    I’ve almost go it sorted except for the latest author comments. The code I’m using pulls in all the comments made by the author and displays the entire comment. What I want to do is to just display the comment excerpt and I only want to display the latest 10 comments.

    In the code below I’ve tried to call comment_excerpt in place of comment_content but this does not work – do I need to do an additional call in my functions file?

    I’ve tried to use a loop on the output of author comments to restrict it to just 10 comments but it did not work. Adding a count to the output is my normal way of restricting output. Is there a way to only pull in the latest 10 comments elsewhere.

    I think the problem I’m having is conflicts with the domtab javascript because I don’t see why doing the above does not work.

    You can see what I’m trying to do here http://wildlifenews.co.uk/author/kevin/

    The code for the author comments I’m using is:

    <a name="comments" id="comments">Latest comments</a>
    <?
    if(get_query_var('author_name')) :
    $curauth = get_userdatabylogin(get_query_var('author_name'));
    else :
    $curauth = get_userdata(get_query_var('author'));
    endif;
    $querystr = "
        SELECT comment_ID, comment_post_ID, post_title, comment_content
        FROM $wpdb->comments, $wpdb->posts
        WHERE user_id = $curauth->ID
        AND comment_post_id = ID
        AND comment_approved = 1
        ORDER BY comment_ID DESC
     ";
    
     $comments_array = $wpdb->get_results($querystr, OBJECT);
    
    if ($comments_array): ?>
    <ul>
    <? foreach ($comments_array as $comment):
    	setup_postdata($comment);
    	echo "<li><a href='". get_bloginfo('url') ."/?p=".$comment->comment_post_ID."'>Comment on ". $comment->post_title. "</a><br />". $comment->comment_content . "</li>";
    endforeach; ?>
    </ul>
    <? endif; ?>
    	</div>
    </div>

    Any help would be appreciated
    thanks
    Kevin

Viewing 1 replies (of 1 total)
  • Thread Starter kevin heath

    (@ypraise)

    OK no problem I’ve sorted both situations out. phew.

    This is the code to diplay the last 10 comments made for an author that you can put on author.php
    Obviously if you want more than 10 comments to show then change the LIMIT number to whatever you want.

    It looks like that the default comment excerpt is set to 20 words which may be a little to small. I’m guessing Ill need to sort out a fnction to change it as I don’t want to change wp core files. Hope the code is of use to someone.

    <?
    if(get_query_var('author_name')) :
    $curauth = get_userdatabylogin(get_query_var('author_name'));
    else :
    $curauth = get_userdata(get_query_var('author'));
    endif;
    $querystr = "
        SELECT comment_ID, comment_post_ID, post_title, comment_content
        FROM $wpdb->comments, $wpdb->posts
        WHERE user_id = $curauth->ID
        AND comment_post_id = ID
        AND comment_approved = 1
        ORDER BY comment_ID DESC
    	LIMIT 10
    
     ";
    
     $comments_array = $wpdb->get_results($querystr, OBJECT);
    
    if ($comments_array): ?>
    <ul>
    <? foreach ($comments_array as $comment):
    	setup_postdata($comment);
    	echo "<li><a href='". get_bloginfo('url') ."/?p=".$comment->comment_post_ID."'>Comment on ". $comment->post_title. "</a><br />". get_comment_excerpt() . "</li>";
    endforeach; ?>
    </ul>
    <? endif; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘2 problems with calling author comments’ is closed to new replies.