Detect inside a custom query the kind of post type to assign custom classes

The post_class function will do this for you automatically within the loop:

<div <?php post_class(); ?>>

which will add some combination of these classes:

  • .post-[id]
  • .[post-type]
  • .type-[post-type]
  • .status-[post-status]
  • .format-[post-format] (default to ‘standard’)
  • .post-password-required
  • .post-password-protected
  • .has-post-thumbnail
  • .sticky
  • .hentry (hAtom microformat pages)
  • .[taxonomy]-[taxonomy-slug] (includes category)
  • .tag-[tag-name]

You can also get just the post type within the loop via the get_post_type function:

<?php echo get_post_type(); ?>