Skip to content

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)

  • comment-default.php – Used when there are no other templates that match for a given comment.
  • ping.php – Used if the comment is a pingback or a trackback.
  • author.php – Used when the author of the post leaves a comment.
  • user-{username}.php – Used when a user with that username leaves a comment. For example, a template with a file name of user-jsmith.php would be used for a comment by user jsmith. Any WordPress username can take the place of {username} in the file name.
  • role-{role}.php – Used when a comment is made by a user with a certain role. For example, a template with a file name of role-subscriber.php would be used for a user with a role of “subscriber” (typical for a registered commentor who is not an author or an admin). Any WordPress role can take the place of {role} in the file name.

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.

Categories: Development.

The General Context

This describes the General 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 General Context works and where it is used. The General Context allows you to customize how general parts of your theme (header, footer, sidebar, etc.) are shown based on information about the type of page being shown.

Scenario #1 – Custom Sidebar

You’re building a personal web site/blog. One of your categories is “Photos”, a place where you post some of your photos and perhaps some of your thoughts on photography. For this section, you want to add a little something extra to your sidebar – you want to include your most recent photo, a Flickr slideshow, etc. at the top of the sidebar.

Using Carrington, this is very simple. You create a new file in your sidebar/ folder called cat-photos.php and Carrington will use this sidebar when showing the category archives for the Photos category.

If you want also use a custom sidebar template for any single post in this category, you can create another template in the sidebar/ directory called single-cat-photos.php. This template will be used for single post views when the post is in the Photos category.

Bingo, you’ve got a custom sidebar that is only used when you want it.

Now you may be thinking “Wait a minute, what about code duplication? I thought that was bad…” – you’re right. However multiple templates doesn’t necessarily mean code duplication. Remember this is all just PHP, you can put your common code in a file called common.php or similar and include that in each sidebar file. Perhaps that file is showing a dynamic sidebar if you’re using dynamic sidebars and widgets. In the scenario above, you might simply include the cat-photos.php file in the single-cat-photos.php file.

Can you do this with conditional code in a single template? Sure. What Carrington gives you two-fold: is a consistent way to manage all of these conditions using simple named templates and the ability to make this change without writing any PHP code (designer friendly!). Also, this is just very a simple example, the more complex the site you are building, the more Carrington will help you out.

Scenario #2 – Custom Headers

You’re building a magazine web site that uses custom header graphics and elements for different categories and author archives. The headers include custom elements like live scores in the Sports category, weather conditions in the Weather category, and a headshot and mini-bio for the author archives.

In this example, you can see how the conditional code in header.php would start to get fairly complex in a traditional WordPress theme.

The files you would create in this scenario are: cat-sports.php, cat-weather.php, author-jsmith.php, authorsjones.php, etc.

In each file put in the HTML, PHP function calls, etc. for the content you need for that category or author archive. Remember, you can include common code into each of these templates from a separate common template if necessary.

General Context Documentation

The Carrington framework enables customizability based on matching contexts and file templates that conform to the Carrington template naming conventions.

The General Context refers to type of page that is being shown. This context is used when selecting a template from the following directories:

  • attachment
  • comments
  • footer
  • header
  • loop
  • posts
  • sidebar
  • single

When choosing a template to use in the General Context, the Carrington engine looks at the type of request is being fulfilled. It will identify the request as the home page, a category archive, and individual post, etc.

There is additional checking done for single post requests. All options in the Content Context are supported here with a ‘single-’ prefix added to the file. See specifics below.

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.

By default, conditions are checked in this order:

  1. author
  2. role
  3. category
  4. tag
  5. single
  6. default (home, search, archive, 404, etc.)

This order can be altered (and added to) using the `cfct_general_match_order` filter.

Supported Templates (General Context)

  • {dirname}-default.php (or default.php) – Used when there are no other templates that match for a given page/post.
  • archive.php – Used for date archives or if there are no specific category, author or tag templates.
  • author.php – Used for author archive lists.
  • author-{username}.php – Used when the post/page is authored by a specific user. For example, a template with a file name of author-jsmith.php would be used for a post/page by user jsmith. Any WordPress username can take the place of {username} in the file name.
  • role-{rolename}.php – Used when the post author has a particular role. This might be the role of contributor, author, editor, etc. and use a file of role-contributor.php, role_author.php, etc. where the role name takes the place of the {rolename} in the file name.
  • category.php – Used for category archive lists.
  • cat-{slug}.php – Used fr displaying a given category. The category is matched by the “slug” – for example a post in category “General” (with a category slug of “general”) could use a template of cat-general.php.
  • home.php – Used when on the home page.
  • page.php – Used for pages that do not match any other contextual templates.
  • search.php – Used when displaying search results.
  • single.php – Used for single post pages.
  • single-{content context filenames}.php – Used for single post pages.
  • tag.php – Used for tag archive lists.
  • tag-{slug}.php – Used for displaying a given tag. The tag is matched by the “slug” – for example a post in tag “News” (with a tag slug of “news”) could use a template of tag-news.php.

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

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

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

Categories: Development.

Carrington Framework Overview

This post covers the basic similarities and differences between a Carrington theme and a traditional WordPress theme, and the core functionality of the Carrington CMS theme framework. Please read the Q&A first before reading this overview.

Themes created with the Carrington framework work much in the way a traditional WordPress theme does, the difference is in how the code is abstracted and what can be done with those abstractions. The initial response when seeing more files and folders in a Carrington theme seems to be “wow, this is complicated”, but the general process is no different than a traditional WordPress theme.

Here is a diagram that shows the difference between the page load for a single post view in the WordPress Default theme and how the same in done in Carrington:

flow

In this diagram, the items in bubbles are pulled in as included files and the items without bubbles are hardcoded into a parent file.

As you can see, the same things are loaded in the same order. If you dig in and look at the code, you’ll see that the same WordPress template functions are used in both. The difference is in how the template files are structured.

The WordPress Default theme basically follows this code path:

  • Load single.php
  • single.php includes header.php
  • “the loop” is hardcoded into single.php
  • “the content” is hardcoded into “the loop” portion of single.php
  • single.php includes comments.php, which displays the list of comments and the add comment form
  • single.php includes sidebar.php
  • single.php includes footer.php

You’ll note that code is hardcoded into single.php and comments.php. This prevents you from re-using that code in other places in the theme the way that more atomic templates for these items would.

Now let’s look at the code path for a Carrington theme:

  • Load single.php
  • single.php asks the Carrington framework to look for appropriate top page templates in the single/ directory and includes the proper template.
  • Next we include a header file – the Carrington framework looks for an appropriate header templates in the header/ directory and includes it.
  • The next include is a loop from the loop/ directory – again, selected from available templates by the Carrington framework.
  • The loop include will then choose either a full content view of the post from the content/ directory or an abbreviated view from the excerpt/ directory. The template is selected by the Carrington framework based on the available templates and the various data attributes of the post.
  • The next include is the comments wrapper from the comments/ directory, again chosen as appropriate by the Carrington framework from available template options for the current page.
  • The comments wrapper holds the comments loop, which then includes the appropriate comment template for each comment from available templates in the comment/ directory.
  • The comment form is brought in from the forms/ directory – having it separate makes it available for re-use in other places as needed.
  • The sidebar is selected by the Carrington framework from available sidebar templates in the sidebar/ directory.
  • The footer is selected by the Carrington framework from available footer templates in the footer/ directory.

There appear to be more steps in this process, but if you look you’ll see they are the same steps that are in the WordPress Default theme. There are more files and folders because we’ve taken care to better abstract the distinct bits and pieces of the theme into discreet atomic templates; enabling better re-use of them.

Duplicating code is bad. Developers know this, it’s why they create functions, objects, include files, etc. to avoid having to maintain the same code in multiple places. Designers know it too. It’s why they create CSS stylesheets instead of hardcoding CSS into style tags for every element. Carrington is built from the ground up around native support for atomic templates for various WordPress theme components (to encourage and enable code re-use).

In the Carrington Blog theme, we use the atomic post templates to be able to load in posts individually from the archive pages with AJAX – see an example here. This isn’t easily possible with the WordPress Default theme because the template code for the individual post isn’t abstracted into a separate file.

Above in the page load process I talk about the Carrington framework choosing from available templates for each piece of the theme. This smart template selection is the primary job of the Carrington framework. It allows you to create rich, customized themes for complex CMS web sites by simply creating different template files instead of coding conditional logic into your template files.

You create templates for various conditions, and the Carrington framework uses those templates when it runs across one of those conditions.

It’s also important to note that you don’t have to create more than one template for anything. You could start your site with just default templates in each folder, and have the ability to expand with easy customization later.

The templates in the different Carrington directories are chosen based on one of three supported contexts:

  1. General Context – what type of page is this (category page, single page, home page, etc.)?
  2. Post Context – what type of post is this (does it have this category, author, tag, custom field, etc.)?
  3. Comment Context – what type of comment is this and who left it (comment, pingback, is the user registered, an author, etc.)?

Note: these contexts can be extended and additional data conditions to check can be added using the hooks and filters in the core Carrington framework.

For example, when choosing the template file to use for the header, the process looks something like this:

  1. Check for available template files in the header/ directory.
  2. Run through conditions from most restrictive to most liberal (the order and conditions are customizable via filter) until a match is found with a template option. When a match is found, use that template.
  3. Use the default template if there is no match found to a condition, or no other templates are present.

Each folder in the Carrington themes we provide (including Carrington JAM, our “starting point” theme) includes a README file that explains the purpose of the files in that folder, what context is supported for that folder, and what template naming conventions are supported in that folder by the Carrington framework.

Hopefully this overview has given you a good base from which to understand the core principles in place in Carrington, and how it is similar and different from traditional WordPress theming. In our next installment, we’ll look at the General Context and how to use it.

Categories: Development.

Carrington JAM (Just Add Markup) 1.2.1

We accidentally mis-packaged Carrington JAM 1.2, leaving out the README files in each directory. Oops!!

This has been rectified with version 1.2.1 – grab it from the themes page.

Also, the documentation is always available on the Crowd Favorite web site and in the public SVN repository on Google Code.

Categories: Announcements, Carrington JAM.

What is Carrington? The Q&A

One of the challenges you face when when you create something new is how best to describe it to people so they understand what it is for and how they can use it. While a number of developers and theme authors have dug into the documentation and example themes and learned how to use Carrington, we’d like to make it a little more accessible to others. We’d also like to clear up some misconceptions about the Carrington framework vs. other WordPress theme frameworks.

To get started with this, we’re going to try a good old O’Grady-style Q&A.

What is Carrington?

Carrington is a new (we think better) way of organizing a WordPress theme, coupled with a core framework engine that provides a bunch of exciting functionality for free, just by creating different named templates.

The Carrington framework is a completely additive framework. It builds on the existing core WordPress theme structure and functionality and uses core WordPress theme functions for easy adoption by experienced theme authors.

You can even use the Carrington framework selectively when creating a theme, more on this later.

Why did you originally create Carrington?

When you spend enough time creating advanced web sites using WordPress you eventually notice a number of things that you find yourself needing to do over and over again. Like any good developer, when you notice patterns you look for ways to automate and re-use functionality. We did this with WordPress themes and Carrington is the result.

Instead of having to create a bunch of conditional statements in theme code, Carrington supports a rich set of named template files and applies them as appropriate based on data conditions (examples: post is in category X, has a custom field of Y or a comment is by a user with a role of Z). Using Carrington allows you to create richer, more complex sites more easily.

At WordCamp SF this year, I was chatting with Adam Tow and he reminded me that I was talking about building this sort of system back in 2007 when we were working on the All Things Digital site together. It’s something I’ve wanted to build for a long time, and I’m really proud of how the idea has been realized with Carrington.

Why is the multiple template approach better than conditional code?

It’s a bit of a generalization, but the multiple template approach is a win over writing conditional code for a number of reasons:

  1. Less code = fewer bugs. It’s a bit of an oversimplification, but writing less code reduces the chance for bugs and edge-cases to sneak into your code.
  2. Fewer reference lookups = faster development. When you don’t have to look up how to access user permissions, if a post is in a certain category, the syntax for checking custom fields, etc. your development is quite a bit faster.
  3. Maintaining your conditional rules all in one place ensures that the logic for your site is consistently applied.
  4. Having the conditional rules all in one place also makes the site easier to maintain. It makes it less likely that you run into unexpected edge cases when adding a new post type, etc. – this sort of issue is common when you have complex conditional code in lots of different places.
  5. Designers/front-end developers have more power. By removing the requirement to write PHP code to achieve custom visual styling is certain situations for posts, comments, sidebars, headers and footers, etc., WordPress theme creation is more accessible for designers and front-end developers that aren’t as comfortable writing PHP.

Multiple templates does have a potential drawback of code duplication, but if you’re smart about how your structure your templates and create includes for common code bits, most of those concerns are non-issues.

How does Carrington differ from other theme frameworks?

A development framework trades convention for code. Basically, you (the developer) agree that you’ll follow certain conventions in your code and as a result you’ll get certain functionality, features, etc. for free as part of the framework you are using.

This is how development frameworks like Rails for Ruby, Django for Python, CakePHP/Symfony/CodeIgniter for PHP work, and it’s how we built Carrington as well.

You use the template naming conventions and directory structure supported by Carrington and you get to write less conditional code.

So it’s not a parent theme?

No, it’s not a parent theme and it isn’t intended to be. I think it’s really unfortunate that people decided to call parent themes theme frameworks. They aren’t frameworks in the standard development sense, they are parent themes that support child themes to override certain components of them.

How do people maintain their changes if they can’t create child themes?

Carrington was created to help build complex web sites that are powered by WordPress. To do this it has added certain conventions that are not well supported by the current parent/child theme system in WordPress.

We may look at submitting core improvements in the future to allow this to work better, but it’s not at the top of the priority list yet.

Why call it a “CMS theme framework”?

When we started building Carrington we called it a theme framework because that’s what it is. However, since “theme framework” has been co-opted to mean “parent theme” this was causing all sorts of confusion.

We changed our terminology to “CMS theme framework” in an attempt to differentiate Carrington from the parent themes out there, while still indicating that it is indeed a framework – a framework intended for creating CMS web sites with WordPress.

Sounds complicated, it’s only for developers?

Not at all. The concepts are strikingly simple, however perhaps because they are somewhat challenging to the WordPress theme status quo and perhaps because we have not produced any tutorials yet, some folks seem to dismiss Carrington as too hard to use.

In fact, the opposite is true – using Carrington makes creating complex WordPress themes and web sites much easier.

How come there are so many files and folders?

With Carrington we took care to re-think and re-conceptualize how we use WordPress themes, and to abstract things at the levels we commonly need to make customizations. We also made sure to keep the same logical flow as a standard WordPress theme so that it would be as easy as possible for people to follow.

It basically boils down to this: where a traditional WordPress theme has a single file, a Carrington-based theme has a folder. Inside that folder can be as many templates as you like and the Carrington framework will choose and select the right file to use based on the page being shown.

This means that at just about every spot in the theme that you need to make a customization, you can do so without needing to write conditional code. You can simply make a new theme with a name that matches the situation you want it used in.

By abstracting the parts of the theme in a more granular way, it also means you have less repetition of code for a more elegantly constructed theme. The WordPress Default theme includes the code to display a post in several different files. Carrington uses the same file (or files, if you have different templates for different post types) in different places – you only have to change things once and they get updated everywhere.

Whare are the benefits for a designer?

Mainly the fact that you don’t have to write PHP code to apply rich, different designs to different posts, comments, sections, etc. You can spend your time working on your design and let the Carrington framework do all the heavy lifting for you.

Why did you release it?

We believe strongly in giving back to the WordPress community. We are thrilled at how powerful the Carrington framework is and how much easier it makes building the sites we work on. We want others to have those same benefits, and perhaps contribute back to Carrington as well.

The Carrington CMS theme framework has always been free, Open Source under the GPL. The code is hosted publicly on Google Code and we’ve even created our Carrington JAM theme to give folks a good starting point for creating a Carrington-based theme.

Why did you release themes based on it?

Again, to give back to the community. Also, we wanted to put out some examples of how the Carrington template abstractions can make certain features (AJAX loading of posts and comments for example) much easier than the traditional WordPress theme file structure.

How do you plan to help people better understand the power of Carrington and how to use it?

Hopefully this Q&A is a start. :)

Besides the thorough reference documentation that is already available and included with each Carrington theme, we’ve been working on some overviews and tutorials that should help explain the power of Carrington and make it more accessible to people.

Thankfully we’ve been very busy at Crowd Favorite this year, and this documentation has often taken a backseat to our project commitments (I started writing this Q&A 2-3 weeks ago). I hope we’ll have more examples and tutorials available soon. We welcome any tutorials, overviews, etc. from the community as well and will be happy to host them here with appropriate credit links.

Categories: Announcements, Development.

Alister Cameron on Carrington

Alister Cameron has a nice video talking about what he sees as the win with the Carrington CMS theme framework.

He obviously “gets it” – we need to do a better job evangelizing and providing examples. We’re working on it – would love to have community contributions around this as well.

Categories: Development.

Changelog

We’ve added a development changelog page to the site here so you can see recent changes to the Carrington framework and themes. This is part of a larger effort to create more developer resources, including some tutorials and overviews of the framework.

Categories: Announcements, Development.

No Depression Archives

The No Depression archives site is home to over 13 years of archival content from the No Depression magazine. There are 20 different article types, over 3700 artists (using a custom taxonomy), and over 7300 articles housed at the site – all neatly categorized and available for your musical reading pleasure.

If you love american roots music, this site is a must-see.

For those of you that got to this page seeking depression help, you can click this link.

Categories: Showcase.

Carrington Blog 2.1

Version 2.1 of Carrington Blog is a patch release to address a couple of compatibility issues with WordPress 2.8.

Carrington Blog

Here are the changes of note:

  • Made the lightbox gallery feature compatible with WordPress 2.8 (specifically, with the included jQuery 1.3).
  • Reduce the size of some included images.
  • Removed page template names from page templates in the pages/ directory due to a bug in WordPress 2.8 that would show them as selectable but would not use them.
  • Updated to Carrington Core 2.4.
  • A patch for backward compatibility with older versions of WordPress.

The download, as always, is available from the themes page.

Categories: Announcements, Carrington Blog.

← Exit Carrington Text Preview