• Assume that you have a movies.php custom page template ( which has room/zones for a nice movie post layout incorporating custom taxonomies such as genre,director,actor etc)….

    How do you establish a default association in between “movies.php template” and the custom post type called “movies” so that WordPress could automatically defaults to movies.php template whenever it detects a movies post type is aout to be served..

    Why do i want that? I think it does not make much sense to select a corresponding page template from the dropdown every single time you want to add a new movie post. If you are going to post 100 movies, chances are you will set the template to movies.php 100 times.

    This kind of functionality exists, when you create a regular page.. wp automatically serves it with the page.php, without us associating the post with the page.php,.. it’s given… right? so why not do the same automatically when creating a new post ( of custom post type X for example) with a template file exactly named as x.php?

Viewing 3 replies - 1 through 3 (of 3 total)
  • you can get wordpress to load a specific single.php depending on what category the post is in…

    I cant remember whether its a widget or functions.php edit – but is that what you’re after?

    Thread Starter MHalukK

    (@mhalukk)

    Here are the steps I’d like to take when I find my solution;

    1. create custom post type, “movies”
    2. throw in a few custom fields for the custom type “movies” -> such as price, description
    3. create a bunch of taxonomies again for the custom type “movies” -> such as genre, director
    4. create a custom template (named specially movies.php following the convention [custom_post_type_name_here].php) which does a nice job in displaying movie post with its price, description, and clickable genre & director

    so far so good… but that’s where my buck stops..

    At this point, I’d like to be able to tell WordPress somehow that from now, on EVERY TIME, I ADD A MOVIE POST, that movie post is going to use movies.php as its page template without me doing anything as far as templates are concerned.

    So WordPress will check the custom post type that the current post is in, and it will automatically look for that_name_here.php in its template hierarchy. So if the custom post type is “recipes”, then it will check for “recipes.php” in the theme to serve the post.

    Am I clear this time?

    So the answer is – yes.

    You want to create a single.php template that detects the category and loads if it is in said category.

    For example if movies is category 10 then the if the post is in the movies category it will be rendered using single-10.php

    here’s how to do it

    https://www.nathanrice.net/blog/wordpress-single-post-templates/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom post types/templates’ is closed to new replies.