Wordpress: custom style / coding for custom post types by index

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!

+3
source share
2 answers

CSS, , , , -

<article class="<?php echo $post->post_type; ?>" ...>

, CSS .

post_class WordPress

<article <?php post_class($post->post_type); ?>>

, - .

, if, post:

if ('my_post_type' == $post->post_type)
{
    // Code Here
}

, .

Codex post_class

+2

:

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;
}       
0

All Articles