McNinja Post Styles

Download McNinja Post Styles on WordPress.org

Every post is unique, but on almost every site, they look the same at first: A title, an excerpt and a featured image. Why not display the most important part of your posts to readers and actually give them a reason to click on your post a read it? That’s what this plugin does.

McNinja Post Styles is what we always wanted Post Formats to be: powerful, flexible and extendable.

McNinja Post Styles can display content based on the Post Style of a post. For example, if your post has a video in it and you’ve selected the ‘Video’ style, your blog page, category pages, etc. will display that video rather than an excerpt.

To enable this functionality, go to Settings->Reading and select “Enable Post Style formatting.”

Post Styles can be selected for a Post from the ‘Edit Post’ screen.

McNinja Post Styles…

* Creates a Post Style taxonomy, allowing authors to choose how to display a Post
* Supports all of the formats added by Post Formats (aside, gallery, link, image, quote, status, video, audio, chat) so that if your theme made use of Post Formats, the same templates can be used.
* Provides a filter hook so that you can add/create your own Post Styles (formats). Why be limited to what’s provided in WP Core?
* Provides a metabox on the Post Edit screen to easily choose the desired style.

Filter Reference

post_style_strings: Array of strings containing existing Post Styles. Used to add new Post Styles or remove existing Post Styles.
Parameters: 1 ( $styles array )
Return: 1 ( $styles array )

post_style_formatting: Boolean to override the setting for enabling Post Style formatting.
Parameters: 1 ( $enabled bool )
Return: 1 ( $enabled bool )

post_style_content_formatting: Used to filter the post content. Style of post is passed in as second parameter.
Parameters: 2 ( $content string, $style string )
Return: 1 ( $content string )

Frequently Asked Questions

How do I make use of Post Styles?

Simply go to Settings->Reading and select “Enable Post Style formatting”, save your changes, and you’re ready to roll!

How do I use Post Styles to display custom theme templates I’ve created?

In your loop or other area in which displaying a content template, change your get_template_part call to the following:

get_template_part( ‘content’, get_post_style() );

get_post_style() will return the slug of the selected post style, for example, if a post is using the ‘image’ Post Style, then get_template_part will be looking to use content-image.php to display the post.

What template will be used if the ‘Standard’ post style (default) is selected?

By default, it will look for content-post.php, if there is no content-post.php, it will use content.php

How do I add CSS to a specific Post Style?

Posts will have a class associated with their style. The class name is in the form of ‘post-style-(slug-name)’, so a post using ‘image’ can be targeted with the ‘.post-style-image’ class.

How do I add a new Post Style?

The ‘post_style_strings’ filter allows you to add new styles. It provides an array of Post Styles and you can add your new post style. The example below adds a new post style named ‘Golden Unicorn’, with a slug ‘golden-unicorn’.

function my_new_custom_post_style( $strings ) {
$strings[‘golden-unicorn’] = _x( ‘Golden Unicorn’, ‘Post style’ );
return $strings;
}
add_filter( ‘post_style_strings’, ‘my_new_custom_post_style’);

Screenshots

Post Style metabox added to Post Edit screen

screenshot-1

Example of a post stream utlizing McNinja Post Styles with ‘video’, ‘image’, and ‘standard’ post styles.

Example of a post stream utlizing McNinja Post Styles with 'video', 'image', and 'standard' post styles.