Display trackbacks separately from comments in twentyeleven

How do I display trackbacks (the link and the date) outside of the twentyeleven comment loop?

The function below is from the twentyeleven functions.php file. I’m using the standard comments.php file from twentyeleven, and the trackbacks are shown under the comments when using <?php comments_template( '', true ); ?> in a template file. I can delete that, but while keeping the normal comments display, how do I display pings in other areas of a template file all by themselves?

Read More

(Yes, I’m using a child theme.)

if ( ! function_exists( 'twentyeleven_comment' ) ) :
/**
 * Template for comments and pingbacks.
 */
function twentyeleven_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
        case 'pingback' :
        case 'trackback' :
    ?>
    <li class="post pingback">
        <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
    <?php
            break;
        default :
    ?>

Related posts

Leave a Reply

2 comments

  1. Use the typeparam in the function wp_list_comments().
    Copy the comments.php to your Child Theme. search for wp_list_comments. Find this:

        <ol class="commentlist">
            <?php
                /* Loop through and list the comments. Tell wp_list_comments()
                 * to use twentyeleven_comment() to format the comments.
                 * If you want to overload this in a child theme then you can
                 * define twentyeleven_comment() and that will be used instead.
                 * See twentyeleven_comment() in twentyeleven/functions.php for more.
                 */
                wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) );
            ?>
        </ol>
    

    Change this with your Params, like this:

        <ol class="commentlist">
        <?php
            // only comments
            wp_list_comments( array( 'type' => 'comment', 'callback' => 'twentyeleven_comment' ) );
    
            // only pingbacks
            wp_list_comments( array( 'type' => 'pingback', 'callback' => 'twentyeleven_comment' ) );
        ?>
        </ol>
    

    You can also use the param value pings, there have include trackback and pingback; maybe you will only show pingback, then use the value pingback for the valueparam. Also you can change the markup of html to more difference in the output.

    If you will separate the pingback and comments in seperate areas, then like this.

    <ol class="commentlist">
        <?php
            wp_list_comments( array( 'type' => 'comment', 'callback' => 'twentyeleven_comment' ) );
        ?>
    </ol>
    <ol class="pingbacklist">
        <?php
            wp_list_comments( array( 'type' => 'pingback', 'callback' => 'twentyeleven_comment' ) );
        ?>
    </ol>
    

    Now a screenshot of the results to the code above:
    enter image description here

    At last, the param typeand his possibilities:

    $type – (string) (optional)

    The type of comment(s) to display. Can be 'all', 'comment', 'trackback', 'pingback', or 'pings'. 'pings' is 'trackback' and 'pingback' together.

    Default: 'all'

  2. In your comments.php (child theme) you can use something like that:

    <ol class="commentlist">
                <?php
                    /* Loop to show comments  */
                    wp_list_comments('type=comment&avatar_size=64');
                ?>
            </ol>
    

    And then do the same thing for pings…

    <ol class="commentlist">
                <?php
                    /* Loop to show pings  */
                    wp_list_comments('type=pings');
                ?>
            </ol>