Incorporating post formats

By default, to keep things simplified, the framework doesn’t come with post formats enabled. In this article, I don’t want to go through the common topics of actually styling and creating posts for different formats, but try to just give you the relevant information you need to get started in incorporating post formats from your Child theme with this framework.

Note: The methods outlined in this article are what was used in The Arcadian, built on the Theme Blvd framework.

Add post format support

This first part isn’t anything specific to our theme framework, but you just need to add support for the post formats. This is the same thing you’d do in any WordPress theme.

So, within your Child theme’s functions.php you could add support for all available post formats like this:

// Add theme support for all post formats
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );

Reference: Post Formats > Adding Theme Support

Adjusting the template part used

For this section, first make sure you’re familiar with information outlined in the article, Template Parts.

Let’s take a look at the framework’s default template parts for post lists, the homepage, archives, and single posts: Default Template Parts

From looking at the default template parts table, we can see that currently these template part files are being used:

  • content-archive.php – posts in archive pages
  • content-list.php – posts in post lists/homepage
  • content-single.php – post in a single post view

However, to create a more standard blog setup we want to pull a file content-{post_format}.php for all of those scenarios. So we can do the following from our Child theme’s functions.php.

// Use content-{post_format}.php for listing posts
function my_template_parts( $parts ) {
	
	global $post;

	// Determine post format where relevant
	$post_format = '';
	if( is_object($post) ) 
		$post_format = get_post_format();

	// Adjust template parts
	$parts['index'] = $post_format;
	$parts['list'] = $post_format;
	$parts['list_paginated'] = $post_format;
	$parts['list_slider'] = $post_format;
	$parts['single'] = $post_format;
	$parts['archive'] = $post_format;

	return $parts;
}
add_filter( 'themeblvd_template_parts', 'my_template_parts' );

Creating the new template part files

Now that we’re calling template parts based on the post formats, we’d need to create a file for each post format within our Child theme’s directory for how its content will be displayed.

  • content-aside.php
  • content-gallery.php
  • content-link.php
  • content-image.php
  • content-quote.php
  • content-status.php
  • content-video.php
  • content-audio.php
  • content-chat.php

With how we have it setup now, any of those files we leave out of our Child theme will result in that post format using “content.php” as a fallback. For example, notice on that list, I didn’t put a “content-standard.php” – This means that if the WordPress user selects the standard post format, it will simply pull “content.php” for that post being displayed in archives, post lists, the homepage and on single posts.

Conclusion

So, the gist is that you’d need to add support for post formats in the same way you would in any WordPress theme and then just adjust which template part the framework pulls when looping through posts in a blogroll. You can then create an template part file for each post format within your Child theme’s directory.

// Add theme support for all post formats
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat' ) );

// Use content-{post_format}.php for listing posts
function my_template_parts( $parts ) {
	
	global $post;

	// Determine post format where relevant
	$post_format = '';
	if( is_object($post) ) 
		$post_format = get_post_format();

	// Adjust template parts
	$parts['index'] = $post_format;
	$parts['list'] = $post_format;
	$parts['list_paginated'] = $post_format;
	$parts['list_slider'] = $post_format;
	$parts['single'] = $post_format;
	$parts['archive'] = $post_format;

	return $parts;
}
add_filter( 'themeblvd_template_parts', 'my_template_parts' );