I am really struggling with Google because of this problem. I set up custom post types, and I managed to include these custom types on the index page. But now I really need a way to style these posts in different ways with regular posts. Does anyone know how I can do this? This is not just styling, but also replacing / adding / removing specific code, as custom types work / look different with regular messages.
Any help would be greatly appreciated!
CSS, , , , -
<article class="<?php echo $post->post_type; ?>" ...>
, CSS .
post_class WordPress
post_class
<article <?php post_class($post->post_type); ?>>
, - .
, if, post:
if ('my_post_type' == $post->post_type) { // Code Here }
, .
Codex post_class
:
if ( 'custom_post_type' == get_post_type() ){ //do whatever }
, , :
switch ( get_post_type() ) { case 'post': //do whatever; break; case 'custom_post_type_1': //do whatever; break; case 'custom_post_type_2': //do whatever; break; }