Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

52 PART I • Getting Started with WordPress


A post published in accordance with the options selected in Figure 3-4 will show up with a
blue background when using Twenty Thirteen. This obviously differs among themes.

So what’s the purpose of using post formats? Well, for starters, they add new CSS classes for
you to play with. The aside post format will add the format-aside class, for example
(see Figure 3-5), an alternative to using a dedicated asides category. This can be very handy.
You’ll also get added classes from body_class() that should sit in your body tag, giving
you further control.

Figure 3-5: CSS classes added to the aside post, styled using the format-aside class.

The real power comes into play when you use conditional tags within the loop. You can check
whether a post is in a certain post format and act on it, like so:

<?php
if ( has_post_format( 'aside' ) ) {
echo 'This is an aside post so expect it to be short!';
}
?>

To add this functionality to your theme, you’ll have to use add_theme_support() in your
functions.php file, telling WordPress which post formats your theme supports by passing an
array. If you want to support the aside, gallery, and video post formats, for example,
you would add this to functions.php:

add_action( 'after_setup_theme', 'smashingtheme_setup' );
function smashingtheme_setup() {
// Add post formats
Free download pdf