I'm working with post formats, most of my code looks similar to this:

if ( has_post_format( 'standard' )) {
  echo '<?php get_sidebar(); ?>';
if ( has_post_format( 'aside' )) {
  echo 'this is an aside';
if ( has_post_format( 'chat' )) {
  echo 'this is the video format';

But I also want one of the if statements to include how to call it if the user did not select a post format. Anybody know?


use get_post_format:

$format = get_post_format();
if ( false === $format )
    echo "no post format";

EDIT - an example using a switch statement:

$format = get_post_format();
switch( $format ){
    case "aside":
        echo "aside";
    case "chat":
        echo "chat";
        echo "standard";
  • Ooh... you were quicker on the draw! ;) – Rev. Voodoo Jun 30 '11 at 15:53
  • Thanks for the help! Is there a way to integrate this into my current statement? – Lucas Jun 30 '11 at 15:58
  • @Lucas - see my edit above. – Milo Jun 30 '11 at 16:15
  • I just realized this isn't working properly. It pulls the excerpt up for all post formats even if it's only supposed to pull it up if there is no post format. – Lucas Jun 30 '11 at 16:29
  • I'd have to see it in context. note that "standard" isn't a format. you'll see it in the UI when none is selected, but get_post_format will return false for "standard". – Milo Jun 30 '11 at 16:34

If they don't assign a format, it gets standard I think, for css purposes?

<?php $format = get_post_format(); 
if ( false === $format ) 
    $format = 'standard'; 
    get_template_part( 'format', $format ); ?>

Is some of the if logic I use, checking for format to return false for conditionals

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.