How to create post format

WordPress 3.1 is here, bringing the much anticipated “post formats” option to sites around the world. You will now be able to specify what type of content you want to publish whether it be a standard text article, image, video, audio clip, quote, link, and more.

Post Formats are a really cool feature introduced in WordPress 3.1 that give you the ability to choose the format the post will be outputted in. These “formats” typically refer to the layout of the post content as displayed by the theme on the front end. So, by using Post Formats, you compile a layout that is displayed for all “video” posts, and then a completely different layout for all “image” posts.

Here on this post, i will give you the example, there are 5 post formats:

  1. Standard – this is used for all regular posts.
  2. Aside – typically styled without tittle. Similar to a Facebook note update.
  3. Link – A link to another site. Themes may wish to use the first <a href=””> tag in the post content as the external link for that post. An alternative approach could be if the post consists only of a URL, then that will be the URL and the title (post_title) will be the name attached to the anchor for it.
  4. Image – A single image. The first <img /> tag in the post could be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.
  5. Video – A single video. The first <video /> tag or object/embed in the post content could be considered the video. Alternatively, if the post consists only of a URL, that will be the video URL. May also contain the video as an attachment to the post, if video support is enabled on the blog (like via a plugin).

Each of these formats has a predefined style (set by the theme developer) that is automatically applied to the post on the front end.

What I want to show you in this tutorial is how we developers (this will get pretty technical, so beware if you’re not a developer) can utilize post formats to greatly improve our WordPress themes, both in terms of flexibility and end user experience.

Let’s start to create post format.

1). Please open your function.php and add this code

$my_post_formats = array( 'video', 'image' ,'aside', 'link' );
add_theme_support( 'post-formats', $my_post_formats );

2). And to make different show post in post format you can use if ( has_post_format( 'post-format' ) please see this example

<?php if ( has_post_format( 'aside' )){ ?>
<li><a href="<?php echo get_post_format_link('quote');?>"><?php echo __('Aside');?></a></li>
<?php }elseif ( has_post_format( 'image' )){ ?>
<li><a href="<?php echo get_post_format_link('image');?>"><?php echo __('Photo');?></a></li>
<?php }elseif ( has_post_format( 'link' )){ ?>
<li><a href="<?php echo get_post_format_link('link');?>"><?php echo __('Link');?></a></li>
<?php }elseif ( has_post_format( 'video' )){ ?>
<li><a href="<?php echo get_post_format_link('video');?>"><?php echo __('Video');?></a></li>
<?php }else{ ?>
<li><a href="<?php echo add_query_arg( 'filter','standard',remove_query_arg('post_format'));?>"><?php echo __('Note');?></a></li>
<?php }?>

add that’s code in your single.php

And finish, you can see at the post (Dashboard->Posts->Add New), Format post is appear now.That is very simple yeah…

You can try that code with your WordPress Themes, and if any question you can give the comment or sent me email. Goodluck…. 🙂


2 thoughts on “How to create post format

  1. Hi I try to follow ur instructions, but i just don’t know how to open “function.php” i think i can’t because i have a pay-theme so i cannot do many things. Would u help me?
    i just want to change my format THANK U!

    1. Thanks for like my post. If you use pay-theme, you can go to Dashboard->Appearance->Editor. At there you can find the function.php and put the script. good luck 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s