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 looking to display an image for all the "standard" post formats on my site. I have done some research on how to add quote, video, photo, etc and have been able to implement these images into the site but when it comes to the "standard" post type I get nothing!

I have done all the necessary steps in the functions.php file:

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

And my code to display the images is as follows:

<div class="post-format">

<?php if(has_post_format('video')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/video.png" alt="Video" />
    <?php } ?>

<?php if(has_post_format('image')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/photo.png" alt="Photo" />
    <?php } ?>

<?php if(has_post_format('standard')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/text.png" alt="Text" />
    <?php } ?>

<?php if(has_post_format('audio')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/audio.png" alt="audio" />
    <?php } ?>

<?php if(has_post_format('aside')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/aside.png" alt="aside" />
    <?php } ?>

<?php if(has_post_format('gallery')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/gallery.png" alt="gallery" />
    <?php } ?>

<?php if(has_post_format('link')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/link.png" alt="link" />
    <?php } ?>

<?php if(has_post_format('quote')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/quote.png" alt="quote" />
    <?php } ?>

<?php if(has_post_format('status')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/status.png" alt="status" />
    <?php } ?>

<?php if(has_post_format('false')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/standard.png" alt="standard" />
    <?php } ?>

<?php if(has_post_format('chat')) { ?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/chat.png" alt="chat" />
    <?php } ?>

Can anyone help me out on how to get the standard post images to display?

share|improve this question
add comment

2 Answers

Technically speaking, there is no "standard" Post Format. Rather, "standard" is simply the default - as in, no Post Format type is defined.

If no Post Format type is defined, get_post_format() simply returns null.

I would suggest re-factoring your code above, and re-naming your icon images using the exact Post Format string. That way, you could do:

<div class="post-format">

<?php $format = get_post_format(); ?>

<?php if( $format ) { ?>
    <img src="<?php echo home_url(); ?>/post-icons/<?php echo $format; ?>.png" alt="<?php echo $format; ?>" />
<?php } else { ?>
    <img src="<?php echo home_url(); ?>/post-icons/standard.png" alt="Standard" />
<?php } ?>

</div>

Or perhaps:

<div class="post-format">

    <?php $format = ( get_post_format() ? get_post_format() : 'standard' ); ?>

    <img src="<?php echo home_url(); ?>/post-icons/<?php echo $format; ?>.png" alt="<?php echo $format; ?>" />

</div>

Either one should work.

share|improve this answer
add comment

Try this code instead of your block:

<?php 
$format = get_post_format();
if ( false === $format ) {
?>
    <img src="<?php bloginfo('template_url'); ?>/post-icons/standard.png" alt="standard" />
<?php 
}
?>
share|improve this answer
add comment

Your Answer

 
discard

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