Difficulty with PHP function that displays a post’s format in WordPress

I am working on a WordPress theme using Bones. I would like to be able to show some text just above the title of each post if the post is either featured, password protected or private.

So far I came up with the following – this is directly inserted into index.php, single.php, archive.php and search.php (not in a function in functions.php)

Read More
<?php if(is_sticky()): ?>
  <h6 class="post-format"><?php _e('Featured', 'bonestheme'); ?></h6>
<?php endif; ?>
<?php if($post->post_password): ?>
  <h6 class="post-format"><i class="icon-lock"></i> <?php _e('Protected', 'bonestheme'); ?></h6>
<?php endif; ?>
<?php if($post->post_status == 'private'): ?>
  <h6 class="post-format"><i class="icon-ban-circle"></i> <?php _e('Private', 'bonestheme'); ?></h6>
<?php endif; ?>

The code above works fine, however, I would like to improve it and put it a function in functions.php. So far I have come up wit the following.

function print_post_format(){

if(is_sticky()):
  printf( __( '<h6 class="post-format">%s</h6>', 'bonestheme' ), 'Featured' );

else($post->post_password):
  printf( __( '<h6 class="post-format"><i class="icon-lock"></i>%s</h6>', 'bonestheme' ), 'Protected' );

else($post->post_status == 'private'):
  printf( __( '<h6 class="post-format"><i class="icon-ban-circle"></i>%s</h6>', 'bonestheme' ), 'Private' );

endif;
}

When calling this function, ‘Featured’ shows up, however, ‘Protected’ and ‘Private’ do not. Any help would be greatly appreciated.

Thank you,
Ian

Related posts

Leave a Reply