Child Themes:Adding Post Formats

From StartBox Docs

Jump to: navigation, search

Contents

Description

Formatting content differently is now easier than ever thanks to the Post Formats feature added with WordPress 3.1. The following documentation is taken straight from the Post Formats Codex page.

Adding Support

<?php add_theme_support('post-formats', $supported_formats ); ?>

Default Usage

<?php $supported_formats = array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ); ?>
Note:If you don't specify an array of supported formats then there will be no formats for users to use.

The above example adds support for all of the standard post formats that WordPress supports.

Using Post Formats

In your child theme theme, make use of get_post_format() to check the format for a post, and change its presentation accordingly. Note that posts with the default format will return a value of FALSE. Or make use of the has_post_format() conditional tag:

if ( has_post_format( 'video' )) {
  echo 'this is the video format';
}

Styling Post Formats

An alternate way to use formats is through styling rules. Themes should use the post_class() function in the wrapper code that surrounds the post to add dynamic styling classes. Post formats will cause extra classes to be added in this manner, using the "format-foo" name.

For example, one could hide post titles from status format posts in this manner:

.format-status .post-title {
display:none;
}

External Resources

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox