0
votes

I'm currently using the underscores.me framework to develop a wordpress theme. I'll be using a handful of custom post types in the theme, with more being added as time progresses so am wondering how to make an array to get the various template files to be recognized. Currently on my index.php I am using the following -

<?php   if( array('movies','books') != get_post_type() ) {
    get_template_part( 'content', get_post_format() );} 
        ?>

        <?php if( 'movies' == get_post_type() ) {

        get_template_part( 'content', 'movies' );}

        elseif( 'books' == get_post_type() ) {

        get_template_part( 'content', 'books' );}

        ?>

I had to make the if arguments for the content-movies.php file to be finally recognized, and what I'd like is

a> to make the non custom post type posts only use content.php

b> an if array to look for the various post types e.g. movies, books, editorials

c> to make each custom post type look for its appropriate content-[post type].php AND single-[post type].php

So far I've been succesful in achieving a> but for b & c the issue I'm having is that my second post type,'books', i still using the content.php file instead of content-books.php. [EDIT] to be clear it's causing a duplicate of book post types appearing in the index, one using content-books.php and the other using content.php

I also had to add some custom code to the functions.php files to get CPT's working, and can show that too if it's suspected to be the cause.

1

1 Answers

0
votes

Try

<?php   if( in_array('movies','books') != get_post_type() ) {
      get_template_part( 'content', get_post_format() );} 
    ?>

    <?php if( 'movies' == get_post_type() ) {

    get_template_part( 'content', 'movies' );}

    elseif( 'books' == get_post_type() ) {

    get_template_part( 'content', 'books' );}

    ?>