Support » Fixing WordPress » is_page_template doesn't work for custom post type templates

  • Hello,

    I am using the code below in my sidebar.php to call different sidebars. However, it isn’t able to call the custom post type, movies, single-movies.php page template because it’s a custom post type. Is there a is_custom_post_type_template? Or something similar?

    Thanks for all the help.

    Jason

    <?php
    if ( is_page_template('single-movies.php') ) { ?>
        <?php dynamic_sidebar( 'movies' ); ?>
    <?php } else { ?>
        Do other stuff
    <?php } ?>

    [Please post code snippets between backticks or use the code button.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • I noticed your other posts, so I figured I’d weigh in:

    WP’s support of custom post types is tentative at best, and it’s an uphill battle.

    Each content type will get a single-{type}.php template file dedicated to it. Use that — it’s way cleaner to rely on that to drive your logic than it is to pollute your templates with PHP. Inside your single-movie.php, for example, you can reference a different sidebar to use.

    E.g. inside your single-movie.php use this

    get_sidebar('movie');

    Whereas inside your template’s single.php, then you could use the default

    get_sidebar();

    Read up on the docs to see how to use the function:
    http://codex.wordpress.org/Function_Reference/get_sidebar

    It’s basically a glorified include statement.

    This should work.

    <?php
    if ( $post->post_type = "movie") ) { ?>
        <?php dynamic_sidebar( 'movies' ); ?>
    <?php } else { ?>
        Do other stuff
    <?php } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_page_template doesn't work for custom post type templates’ is closed to new replies.