• Resolved verseleo

    (@verseleo)


    Hello,

    I have some custom post type that I will assign a separate template for them.
    Now, on index.php file in line 73 is:

    <?php
    // Get post entry content
    if ( is_post_type_archive( 'cpt' ) ) {
    get_template_part( 'partials/cpt-entry/layout' );
    }
    // All other post types.
    else {
    get_template_part( 'partials/entry/layout', get_post_type() );
    } ?>

    How to call template files for other CPT on OceanWP?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Amit Singh

    (@apprimit)

    Hello,

    Follow the below steps to do it –

    1. Install and activate the oceanwp child theme
    2. Now create templates for CPT as per your need in the child theme
    3. Copy the index.php file into the child theme and open it using a code editor
    4. Now edit the code and call your custom template. The path of the file should be correct in the get_template_part function.

    Also, follow this thread – https://www.ads-software.com/support/topic/custom-category-template-to-oceanwp/

    Thread Starter verseleo

    (@verseleo)

    Thanks @apprimit

    My main problem is how to call 2 template at index.php?
    By the code below, every post will be repeated!

    <?php
    // Get post entry content
    if ( is_archive(array( 'cpt1' ) ) ) {
    get_template_part( 'partials/cpt1-entry/layout' );
    }
    if ( is_archive(array( 'cpt2' ) ) ) {
    get_template_part( 'partials/cpt2-entry/layout' );
    }
    
    // All other post types.
    else {
    get_template_part( 'partials/entry/layout', get_post_type() );
    } ?>

    Thanks

    Amit Singh

    (@apprimit)

    Try the below code –

    <?php
    // Get post entry content
    if ( is_archive('cpt1') ) {
    get_template_part( 'partials/cpt1-entry/layout' );
    }
    else if ( is_archive('cpt2') ) {
    get_template_part( 'partials/cpt2-entry/layout' );
    }
    
    // All other post types.
    else {
    get_template_part( 'partials/entry/layout', get_post_type() );
    } ?>
    • This reply was modified 5 years ago by Amit Singh.
    Thread Starter verseleo

    (@verseleo)

    Oh, I can’t thank you enough dear Amit.
    My problem was only & only else ??
    Thank you very much; your support is greatly appreciated.

    Amit Singh

    (@apprimit)

    You’re welcome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Assign separate template for CPT’s’ is closed to new replies.