1

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?

(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 :
    ?>

2 Answers 2

4
+50

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'

4
  • But this kills all comments. While keeping the normal comments display, how do I display pings in other areas of a template file all by themselves? Commented Oct 26, 2012 at 19:43
  • The normal comments get with the type comment and do you will display this in other area then create for all output a custom markup, like ol
    – bueltge
    Commented Oct 28, 2012 at 18:28
  • 1
    Now, I have update that you can see a result of the code in the answer.
    – bueltge
    Commented Oct 28, 2012 at 19:01
  • @bueltge, thanks! That works. I have a lot to learn about functions. Commented Nov 1, 2012 at 14:01
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>
2
  • But this kills all comments. While keeping the normal comments display, how do I display pings in other areas of a template file all by themselves? Commented Oct 26, 2012 at 20:16
  • Ahhh, sorry, i misunderstood your question and thought you only wanted to tear pings apart from comments :) I guess the other reply has more details and maybe is more helpful.
    – versvs
    Commented Oct 31, 2012 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.