Support » Fixing WordPress » Page Templates in Custom Post Types

  • Hi guys,

    I’m trying to use a different page templates with a custom post type I’ve created, but I can’t get the option to show up even though I’ve followed all the guides to doing so to the letter.

    Here’s the code i’m using at the top of the page template:

    Template Name: Hub
    <?php get_header(); ?>

    Here’s the code i’m using to create the custom post type:

    register_post_type('hubs', array(
    'menu_icon' => get_bloginfo('template_directory') . '/images/reviews.png',  // Icon Path
    'label' => 'Hubs',
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'page',
    'hierarchical' => true,
    'query_var' => true,
    'supports' => array(
    ) );

    and here’s the filename I’ve given the page template:

    Any guidance you guys could offer would be greatly appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • First question:
    Are authors using this post type going to have the option to choose this template or the default template; or are you simply trying to apply a specific template to all posts of this type?

    If you want all posts of this type to use your custom template, you don’t want to go about it this way. Instead, you want to call your template file single-hubs.php (and, if you need an archive template for this post type, you can create a template file called archive-hubs.php).

    If you really do want authors to be able to choose between this template and the default template, I’m not sure that’s possible without creating your own custom metabox.

    Even though the documentation in the Codex says the page-attributes flag will enable template and menu order, the source code for WordPress tells a different story. The template selector is hardcoded only to show up when editing a post with page set as its post type (looking through the ticket history, it looks like this change was made somewhere between 3.0 and 3.2).

    I was hoping to be able to select the different templates but I may have to goo back to the drawing board on that one. Kept trying to enable it for hours last night 🙂 You the man sir!

    Well, there’s no reason you can’t use custom post meta to allow authors to select a template. It would take a bit of work, but it’s definitely possible.

    I’ve been trying to get this same thing to work, from both the directions mentioned here.

    I’ve tried to implement Page Templates for my custom post type portfolio and, while the other Attributes show (Order and Parent) the Template dropdown still doesn’t show.

    After reading through the above discussion, I tried creating a single-portfolio.php template to display each of posts in the custom post type portfolio but they still display using the default single.php.

    As you said, Curtiss Grymala, I don’t need authors to be able to select different templates–I just want to display each of these posts in the same way.

    Any thoughts? harlemS, did you get yours to work? Thanks in advance.

    Interestingly enough, this problem reared it’s ugly head again a few days ago. I’ve recently started working on custom function for to this for me but let’s just say it doesn’t quite work yet. I’ll keep at it and let you know if I ever do though Mr. Paperback sir!

    No one fixed a meta box for templates of cstom types?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Page Templates in Custom Post Types’ is closed to new replies.