Display multiple Custom post type on index

Asked

Viewed 80 times

0

I have a Wordpress template with Multiple post type, and I can query and display all Custom post type on index.

My Custom post type is an area reserved only for Movies, Series and Blog, only in my index I only show the Movies and Series because they appear the same.

Ex. how it appears in my index:

Ex

How my blog post appears:

Ex2

But my doubt and the following, as I can show all these posts in my index, like, I use a different model in the area of the blog, I show only an image and a description, already in my area of movies and series I show various information.

How do I distinguish posts to display all on index and without getting bugged?

<?php $args = array('post_type'=>array('filmes', 'series')); query_posts($args); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php   if (has_post_thumbnail()) {
    $imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'home');
    $imgsrc = $imgsrc[0];
} elseif ($postimages = get_children("post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=0")) {
    foreach($postimages as $postimage) {
        $imgsrc = wp_get_attachment_image_src($postimage->ID, 'home');
        $imgsrc = $imgsrc[0];
    }
    } elseif (preg_match('/
        <img [^>]*src=["|\']([^"|\']+)/i', get_the_content(), $match) != FALSE) {
        $imgsrc = $match[1];
    } else {
        $imgsrc = get_template_directory_uri() . '/images/no-imagen.png';
    } ?>

I know that to display blog area posts just add in the array after post_type, but when it appears buggy the view part.

Ex.:

Ex3

  • 1

    You can make a if using the function response get_post_type

  • You could give me an example of how to get started, I’m not good at PHP, just manjo in html and css, PHP I just untangled by the tutorials.

  • 1

    Example. Within that if, just assemble the layout in accordance with the post type.

  • used and it worked, however, I will have to modify the entire template, because only to show the post of a movie I make the query of approximately 10 different taxonomies to display the values, I used the function 'echo' to show, there is some other method to display without having to adapt the code, I mean, just paste the pure code without having to do the queries and then display it like '.$value.'

  • type, to query the quality for example, I use this function "<? php if($values = get_post_custom_values("item_quality")) { ? ><? php echo $values[0]; ? ><? php } ? >" how do I put it inside if without having to adapt it to '.$value.'

1 answer

0

Following the suggestion of the user @Valdeir Psr

<?php if ( get_post_type( get_the_ID() ) == 'filmes' ) {
    echo 'postagens no custom post type filmes';
} elseif ( get_post_type( get_the_ID() ) == 'series' ) {
    echo 'postagens no custom post type series';
} elseif ( get_post_type( get_the_ID() ) == 'blog' ) {
    echo 'postagens no custom post type blog';
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.