Carrington



« | »

The Comment Context

This describes the Comment Context, a concept in the Carrington CMS theme framework for WordPress. Before reading this, you should read the Q&A and the Framework Overview.

In this article we will review some real world examples and cover how the Comment Context works and where it is used. The Comment Context allows you to customize how comments are shown based on information about the comment and the person who left the comment.

Scenario #1 – Registered Users

On a site that wants to encourage our visitors to register, giving registered users enhanced comment displays is a nice approach to take. Perhaps the standard comment display shows just the commentor’s name, but a comment by a registered user shows their name, a link to their web site, a photo, etc.

Accomplishing this with Carrington is very simple. You don’t have to write any conditional PHP code, you can simply create a new comment template and Carrington will do the rest.

Assuming registered users have a role of “Subscriber”, we create a template file named role-subscriber.php and place it in the comment/ folder. In that template file you include the HTML for the links, etc. that you want to display for your registered users. Carrington will use that file for comments by registered users.

Scenario #2 – Pingbacks

You may want to have custom displays for pingback and trackback comments to differentiate them from other comments. Perhaps you want to display a small screenshot of the page that has sent the pingback to your post.

Doing this custom display is easy with Carrington. Simply create a ping.php file in the comment/ directory, and place the HTML and associated code for the web site thumbnail into that template. When displaying a comment that is a pingback or a trackback, Carrington will use this template file – showing your site thumbnail as well.

No need to inline conditional PHP code in your template, just create templates for the conditions you care about and the Carrington engine will take care of the rest.

Scenario #3 – Celebrities

If you are running a site in which certain individuals are very important, you may want to take advantage of the Carrington feature which allows you to create custom comment templates on a per-user basis.

If you are running a U2 fan site and Bono drops by to leave a comment, you probably want to highlight that comment. To do this, simply create a user-bono.php template (where “bono” is the username) in the comment/ folder and that template will be used for comments by Bono.

This feature can also be useful to distinguish real comments by a particular user from comments by someone else with (or using) the same name.

As you can see, Carrington makes it really easy to create custom comment displays for different situations without writing any conditional PHP code.

Comment Context Documentation

When choosing a template to use in the Comment Context, the Carrington engine looks at the type of comment and the author of the comment to choose which template to use.

A “default” template is required, and will be used when there are no other templates that match a given comment. This could be because no other templates have been created, or because the comment in question doesn’t match the templates that are available.

The order in which these conditions are checked defaults to the following:

  1. ping
  2. author
  3. user
  4. role
  5. default

however this order can be overridden with a plugin using the `cfct_comment_match_order` hook.

Once a template match has been found, no other processing is done.

Supported Templates (Comment Context)

Create templates with names using these patterns and place them into the directories (comment) that use the Comment Context. The templates will be used when a situation arises matching their named condition.

This has been an overview of the Comment Context of the Carrington CMS theme framework for WordPress. You may want to look at the General Context and Post Context next.

Community additions to the documentation and resources for Carrington (including this page) are very welcome.

Posted by Alex King on August 9, 2009.

Categories: Development

3 Responses

  1. Thanks!

    by Admimaatode on Sep 5, 2009 at 4:05 am Reply

  2. Hello. Very nice=)

    by Ninja on Oct 13, 2009 at 8:34 am Reply

  3. How do I limit the number of comments per page in the theme?

    by Andrew on Feb 19, 2010 at 6:00 pm Reply

Leave a Reply

« | »




Recent Posts


Pages



About Carrington

Carrington is a theme platform for WordPress from Crowd Favorite. It includes the Carrington Core, a reactive templating engine that makes it easy to create different visual styles for different site areas and content and Carrington Build, an advanced drag and drop page layout system that enables full editorial control for complex pages. more →
← Exit Carrington Mobile Preview