Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
25% accept rate; if an answer solves your problem or correctly answers your question, you should mark it as "accepted". –  Chip Bennett Jul 6 '11 at 20:02

2 Answers 2

up vote 3 down vote accepted

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";
        break;
    case "chat":
        echo "chat";
        break;
    default:
        echo "standard";
}
share|improve this answer
    
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

share|improve this answer
    
Thanks for the help! –  Lucas Jun 30 '11 at 15:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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