WordPress.org

Forums

is_page_template doesn't work for custom post type templates (3 posts)

  1. kuhio61
    Member
    Posted 3 years ago #

    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.]

  2. fireproofsocks
    Member
    Posted 3 years ago #

    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.

  3. itsbarry
    Member
    Posted 2 years ago #

    This should work.

    <?php
    if ( $post->post_type = "movie") ) { ?>
        <?php dynamic_sidebar( 'movies' ); ?>
    <?php } else { ?>
        Do other stuff
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic