This Post
  • HOME PAGE
  • ABOUT
  • ARCHIVES
  • SITEMAP
 
« How To Style Your Comments - Part 1 How To style your Comments - Part 3 »
 
26
Apr

How to Style Your Comments - Part 2

by admin

xhtml validation
In this second part of the how to style your comments series I will show you how to separate or remove track-backs and pings from the comments. there are many tutorials out there on this subject, but many of them can be confusing to the non programmer as they say find this line and add this after or before it. In fact, I did that in the Create A Wordpress Theme series. This tutorial is different, it shows you all the needed code in comments.php so that you can see exactly where the additional code goes and I think this version is a little cleaner and easier to understand.

Removing The Trackbacks And Pings

The first step is to show only the comments, this is done by adding the code that is in red. If you want to you can stop there if you do not want to show the trackbacks and pings. All the code is doing is testing if the input is a comment, if it is then it goes on to display the comment otherwise it’s a track-back or ping and is ignored.

Showing The Trackbacks And Pings

If you do want to show the track-backs and pings then add the code that is in blue. This will print a header that shows how many track-backs there are followed by a list of them. I’ve added an optional bit of code in purple, you add this only if you want to show that you have no track-backs or pings yet.

Other Fixes

You might have noticed that the default theme uses the h3 tag as a title to different parts of the comment section. To me this is a no-no, the h tag is used to bring the Search Engines attention to the included text. This is fine if you want to try ranking for the phrase ‘No responses’, but it’s not exactly useful hey?

The h tags should only be used within the actual posts, outside of a post you can use the p tag and style it. So in this case we have three h3 tags, you can replace them with the following:

<p class="comhdr">

Don’t forget to change the </h3>’s to </p>. Note that there are other h tags in comment.php, you should really change them all. A little of topic but similar, virtual every theme I have seen uses h2, h3 or h4 tags for the plugin or widget headers - why? I don’t know! These too should be changed as I discussed in the How To Create A Wordpress Theme series.

All that’s left is to style these header tags something like this:

.comhdr {
  font-size: 1.6em;
  margin: 0px;
  color: #000;
}

You will probably have to play around with the font-size and color so that they match your theme.

Here is the section of comment.php that needs to be modified:

<!-- You can start editing here. -->

<?php if ($comments) : ?>
  <h3 id="comments"><?php comments_number('No Responses',
  'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
  <?php $ck_trkcnt = 0; ?>

  <ol class="commentlist">
  <?php foreach ($comments as $comment) : ?>
    <?php $comment_type = get_comment_type(); ?>
    <?php if($comment_type == ‘comment’) { ?>

      <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
        <?php echo get_avatar( $comment, 32 ); ?>
        <cite><?php comment_author_link() ?></cite> Says:
        <?php if ($comment->comment_approved == ‘0′) : ?>
          <em>Your comment is awaiting moderation.</em>
        <?php endif; ?>
        <br />
        <small class="commentmetadata"><a href="#comment-<?php
        comment_ID() ?>" title="">
        <?php comment_date(’F jS, Y’) ?>
        at <?php comment_time() ?></a>
        <?php edit_comment_link(’edit’,'  ’,”); ?></small>
        <?php comment_text() ?>
      </li>

    <?php
      /* Changes every other comment to a different class */
      $oddcomment = ( empty( $oddcomment ) ) ? ‘class="alt" ‘ : ”;
    ?>
    <?php } else { ?>
      <?php $ck_trkcnt++; ?>
    <?php } /* End of is_comment statement */ ?>
  <?php endforeach; /* end for each comment */ ?>

  </ol>
  
  <?php if($ck_trkcnt > 0) { ?>
    <h3>There are <?php echo $ck_trkcnt; ?> Trackbacks</h3>
    <ul>
      <?php foreach ($comments as $comment) : ?>
        <?php $comment_type = get_comment_type(); ?>
        <?php if($comment_type != ‘comment’) { ?>
          <li><?php comment_author_link() ?></li>
        <?php } ?>
      <?php endforeach; ?>
    </ul>
  <?php } else { ?>
    <h3>No Trackbacks Yet</h3>
  <?php } ?>

<?php else : // this is displayed if there are no comments so far ?>

After you have completed this and the last part, you have got a more organized layout for the comments section. I am assuming that you are using Wordpress 2.5 or better still, yesterday version 2.5.1 came out which fixes a lot of problems and a security hole. with that assumption, it means that your installation natively supports gravatar icons. So next time, I shall show you how to use them and how to go to town in styling the actual comments.

Related posts:
  1. How To Create A Wordpress Theme - Part 4
  2. How To Style Your Comments - Part 1
  3. How To Modify A WordPress Theme - Part 4
  4. Trackbacks, Pingbacks, Linkbacks - huh?
  5. How To Create A WordPress Theme - Part 7
Subscribe to RSS feed
stumble me

Tags: comments, css, gravatar, pings, search engines, seo, trackbacks, wordpress 2.5
Category wordpress | Print This Post Print This Post |

There are 9 Comments

  1. Great follow up on part 1

    Scribbled by David Hobson on 26/04/08 at 4:08 pm
  2. Interesting follow up to part 1 Colin. Where I get confused is why you would want to hide trackbacks/pingbacks? Is it that they detract from the other comments?

    Scribbled by Bryan on 27/04/08 at 4:46 am
  3. @Bryan: Yes I think that is part of the reason, it all comes down to the design I guess and what the blog owner thinks is important. For example, what I have shown above will only display the link and no body text. I did this as there is no conversation there usually and visually it sets the trackbacks and pings apart from the ongoing conversation. Others like to put the trackbacks before the comments, it’s all a matter of taste.

    Scribbled by Colin King on 27/04/08 at 2:26 pm
  4. I haven’t read the first part yet but this one helped me a lot. Maybe I will change the codes in my blog later. I really don’t have much time for that.

    Scribbled by Pweng Bee on 28/04/08 at 8:36 am
  5. Awesome follow-up to #1.

    Has anyone else noticed more spam coming in via track-back than normal comments? I’m seriously considering killing them altogether.

    Scribbled by Dennis Edell on 28/04/08 at 2:29 pm
  6. @Dennis: I guess I’ve been lucky so far no spammy trackbacks, but there again this is a relatively new blog (6mths).

    Scribbled by Colin King on 02/05/08 at 2:29 pm
  7. Mines only a month or 2 older then yours…I guess I’m unlucky lol.

    Scribbled by Dennis Edell on 02/05/08 at 2:42 pm
  8. Thanks for the tutorial!

    Scribbled by Paul U on 26/07/08 at 8:51 am
  9. My own blog is just starting and this sort of post is really helpful.

    Scribbled by bushy on 11/08/08 at 9:49 am

What are your thoughts?

What do you think? Leave a comment. Alternatively, write a post on your own blog, this blog accepts trackbacks [trackback].

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Please read the Comment Policy before commenting.

  • Check out one of my favourite sites

    Changes Daily. This is not an Ad!



  • Categories

    • Affiliate Marketing
    • Blogging
    • General
    • Guest Posts
    • List Building
    • Monthly Reports
    • Product Reviews
    • Social Networking
    • Traffic
    • Wednesday Links
    • wordpress
  • Recent Posts

    • A New PC05.11
    • Get More Traffic From Your Tutorials05.8
    • A Surprise In The Mail04.30
    • How To style your Comments - Part 304.28
    • How to Style Your Comments - Part 204.26
    • How To Style Your Comments - Part 104.23
    • The March $100 winner, a problem and a rant04.21
    • Valid XHTML For The EntreCard Widget04.15
  • Bookmarks

    Add to Technorati Favorites
  • Top Commentators

    • bushy (1)
    • Frances (1)
    • Mike McMahon (1)
    • Clint Steiner (1)
    • Mark (1)
 

This site's design and contents are ©2007-2008 by CK Marketing - All rights reserved Worldwide

This blog is protected by Dave's Spam Karma 2: 2252 Spams eaten and counting...