WordPress 3.1 Post Formats

WordPress 3.1 released with some new features. One of them is post_formats. This feature is simple, but it allows wordpress developer to add some pretty good styling options with a single line of code.

Activating WordPress 3.1 Post Formats

To enable wordpress 3.1 post formats just edit your themes functions.php file and add following lines of code inside that file.

add_theme_support( 'post-formats', array( 'aside','chat','gallery','link','image','quote','status','video' ) );

Supported WordPress 3.1 post formats

  • aside – Typically styled without a title. Similar to a Facebook status update.
  • chat – A chat transcript.
  • gallery – A gallery of images.
  • link – A link to another site.
  • image – A single image.
  • quote – A quotation.
  • status – A short status update, usually limited to 140 characters. Similar to a Twitter status update.
  • video – A single video.

Just add those posts format in that parameter array inside add_theme_support()

So If i want to just add “Aside , Gallery, status” then i will call that above add_theme_support() function in functions.php file as

add_theme_support( 'post-formats', array( 'aside', 'gallery','status') );

You will see posts formats added on the Add Post Page like

Use Full Functions to use Post Formats

1] get_post_format( $post->ID )

$post_format=get_post_format( $post->ID);

Check Current Post Format

<?php get_header(); ?>
<div id="main">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div id="post-<?<span class=">php the_ID(); ?>" ></div>
		php
			if ( has_post_format( 'aside' )) {
				echo the_content();
			}

			elseif ( has_post_format( 'chat' )) {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
				echo the_content();
			}

			elseif ( has_post_format( 'gallery' )) {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
				echo the_content();
			}

			elseif ( has_post_format( 'image' )) {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
 				echo the_post_thumbnail('medium');
				echo the_content();
			}

			elseif ( has_post_format( 'link' )) {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
				echo the_content();
			}

			elseif ( has_post_format( 'quote' )) {
				echo the_content();
			}

			elseif ( has_post_format( 'status' )) {
  				echo the_content();
			}

			elseif ( has_post_format( 'video' )) {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
				echo the_content();
			}

			elseif ( has_post_format( 'audio' )) {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
				echo the_content();
			}

			else {
				echo '<h3>';
  				echo the_title();
				echo '</h3>';
				echo the_content();
			}
		?>
	</div>
<?php endwhile; else: endif; ?>
</div>
<?php get_sidebar();  get_footer(); ?>

WordPress Post Formats Further Reading

WordPress Post Formats.
WordPress 3.1 Post Format Reference.

Leave a Reply

Your email address will not be published. Required fields are marked *