• Hi,

    I’ve got a custom post type “projects” which is loading nicely mixed in with all my blog posts in my index.php home page. What I’d like to do is, display the data differently to the other posts.

    Here’s what I’ve got, hopefully someone could help out!

    Thanks!

    <?php if (have_posts()) : while (have_posts()) : the_post();
    
    if (!get_post_format()) {
       get_template_part( 'partials/loop', 'archive' );
    } else
    
    if ( has_post_format( 'aside' )) {
       get_template_part('partials/loop', 'archive-aside');
    } else 
    
    if ( has_post_format( 'gallery' )) {
        get_template_part('partials/loop', 'archive-gallery');
    } else
    
    if ( has_post_format( 'link' )) {
        get_template_part('partials/loop', 'archive-link');
    } else
    
    if ( has_post_format( 'image' )) {
        get_template_part('partials/loop', 'archive-image');
    } else
    
    if ( has_post_format( 'quote' )) {
        get_template_part('partials/loop', 'archive-quote');
    } else
    
    if ( has_post_format( 'status' )) {
        get_template_part('partials/loop', 'archive-status');
    } else
    
    if ( has_post_format( 'video' )) {
        get_template_part('partials/loop', 'archive-video');
    } else
    
    if ( has_post_format( 'audio' )) {
        get_template_part('partials/loop', 'archive-audio');
    } else
    
    if ( has_post_format( 'chat' )) {
        get_template_part('partials/loop', 'archive-chat');
    } else
    
    if ( is_post_type_archive( 'projects' )) {
        get_template_part('partials/loop', 'archive-projects');
    }
    ?>
    
    <?php endwhile; ?>

    [Moderator Note: No bumping, thank you.]

Viewing 1 replies (of 1 total)
  • Thread Starter Gabriel Bajada

    (@gbajada)

    Found the answer here.

    My final code looks like this:

    <?php if (have_posts()) : while (have_posts()) : the_post();
    
        if ( get_post_type( $post->ID ) == 'projects' ){
          get_template_part('partials/loop', 'archive-projects');
        } else
    
        if (!get_post_format()) {
           get_template_part( 'partials/loop', 'archive' );
        } else
    
        if ( has_post_format( 'aside' )) {
           get_template_part('partials/loop', 'archive-aside');
        } else 
    
        if ( has_post_format( 'gallery' )) {
            get_template_part('partials/loop', 'archive-gallery');
        } else
    
        if ( has_post_format( 'link' )) {
            get_template_part('partials/loop', 'archive-link');
        } else
    
        if ( has_post_format( 'image' )) {
            get_template_part('partials/loop', 'archive-image');
        } else
    
        if ( has_post_format( 'quote' )) {
            get_template_part('partials/loop', 'archive-quote');
        } else
    
        if ( has_post_format( 'status' )) {
            get_template_part('partials/loop', 'archive-status');
        } else
    
        if ( has_post_format( 'video' )) {
            get_template_part('partials/loop', 'archive-video');
        } else
    
        if ( has_post_format( 'audio' )) {
            get_template_part('partials/loop', 'archive-audio');
        } else
    
        if ( has_post_format( 'chat' )) {
            get_template_part('partials/loop', 'archive-chat');
        }
    ?>
    
    <?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying Custom Post Types differently in index.php’ is closed to new replies.