Custom post types are pretty neat. By putting the following code (kindly taken from WPRecipes) in your functions.php, you can include all post types in your blog page:
function my_get_posts( $query ) { if ( is_home() || is_feed() || is_search() || is_archive() ) { $query->set( 'post_type', array( 'post', 'tutorial', 'update' ) ); } return $query; } add_filter( 'pre_get_posts', 'my_get_posts' );

That's great, but what if I want all of my post types to be shown on my blog page but look slightly different. Well, you can use get_post_type to do exactly that.
get_post_type requires a post ID to be supplied, so you can use <?php get_post_type(get_the_ID()); ?> inside the loop to check against the current posts' post_type.
You can echo that code inside your post class to allow changes on a purely CSS level, by targeting the my_post_type class. However, if you want to go all crazy and have a completely different output for each post, you could do something like this inside your loop:
<?php $type = get_post_type(get_the_ID()); if ($type == "tutorial") : ?> .. tutorial display .. <?php elseif ($type == "update") : ?> .. update display .. <?php else : ?> .. normal post display .. <?php endif; ?>
And viola! You now have completely customisable post type displays, all in the single loop.
Comments