Pingbacks

From Habari Project

Revision as of 19:01, 21 March 2010 by miklb (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Habari supports the sending and recieving of Pingbacks. Displaying them on your site is simple. Let's go over the code you will need to add to your comments template.

By default Habari grabs all the comments for a given post (normal comments, trackbacks, etc) and sorts them into "buckets" for later use. For instance when we want to display all our comments, we would do something like this:

if ( $post->comments->approved->count ) {
  foreach ( $post->comments->comments->approved as $comment ) {

The code above checks if there are approved comments for this post, and if so begins a loop to process them for display. The code for displaying pingbacks is much the same:

if ( $post->comments->pingbacks->count ) {
  foreach ( $post->comments->pingbacks->approved as $pingback ) {

If there are approved pingbacks for this post they are processed for display. Here is complete sample code to display pingbacks:

<?php if ( $post->comments->pingbacks->count ) : ?>
  <h1>
  <?php $theme->pingback_count($post); ?> <?php _e('to'); ?> <?php echo $post->title; ?>
  </h1>
  <div id="pings">
    <ol id="pings-list">
      <?php foreach ( $post->comments->pingbacks->approved as $pingback ) : ?>
        <li id="ping-<?php echo $pingback->id; ?>">
          <p>
            <?php
              echo "<a href=\"{$pingback->url}\">{$pingback->name}</a> &raquo; {$pingback->content}";
            ?>
          </p>
        </li>
      <?php endforeach; ?>
    </ol>
  </div>
<?php endif; ?>

The default comments template in the k2 theme will show both pingbacks and comments. To show only comments use the following code.

$post->comments->comments->approved->count;

The pingback plugin now has a function to retrieve the number pingbacks. By default, it will use Pingbacks, Pingback, and Pingbacks respectively for zero, one, and many. If you would like to use different terminology you could use something like :

 
<?php $theme->pingback_count($post,'%d Linkbacks','%d Linkback','%d Linkbacks'); ?>
Personal tools