Results 1 to 9 of 9

Thread: Custom Post Types & Custom Post Templates

  1. #1
    vsellis's Avatar
    vsellis is offline Hello World
    Join Date
    Aug 2009
    Posts
    6

    Default Custom Post Types & Custom Post Templates

    I've been really looking forward to today's 2.9 release but realized that support for custom post types != support for custom post templates. I know there are plug ins to facilitate this but does anyone know if there is a "built in" support for post templates to be applied to a custom post type?

    I can certainly code PHP functions, ... to manage this but again, thought this might be built in. Custom post types seem a little less useful with out it.

  2. #2
    greenshady's Avatar
    greenshady is offline Here For The Peanuts
    Join Date
    Jan 2009
    Posts
    170

    Default

    I'm hoping we get something like this in 3.0 along with the other post type stuff coming. My idea would be to have post templates follow this hierarchy and format:

    PHP Code:
    {$post_type}-{$custom_template}.php
    {$post_type}-{$post->post_name}.php
    {$post_type}-{$post->ID}.php
    {$post_type}.php 

  3. #3
    vsellis's Avatar
    vsellis is offline Hello World
    Join Date
    Aug 2009
    Posts
    6

    Default

    Thanks Justin. Kinda what I thought. What you just described is exactly what I was hoping for.

  4. #4
    jpelker is offline Hello World
    Join Date
    Oct 2009
    Location
    Chicago, IL
    Posts
    13

    Default

    Does anyone know of any plugins that fully take into account this new 2.9 post type feature?

    I know of More Fields (which is pretty solid but slightly buggy) and Flutter (which I've never gotten to work), plus Pods, but I can't say whether they're really operating within the way 2.9 intends for this feature to work.

  5. #5
    Elpie's Avatar
    Elpie is offline Here For The Peanuts
    Join Date
    Nov 2009
    Location
    New Zealand
    Posts
    168

    Default

    Custom post types in 2.9 seems like a misnomer to me. This appears to be more of a foundation stone for a feature thats coming later. I'm not sure they are really very useful at this point. (Unless I am missing something here).

  6. #6
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    865

    Default

    Custom post types are now supported in the query, basically. So you can do something like query_posts('post_type=custom'); and similar.

    This is bigger than it seems, because with query support comes easy rewriting support. For example, to have /type/custom only show "custom" posts, I could have this in a plugin:

    PHP Code:
    function post_type_add_custom_urls() {
    add_rewrite_tag('%post_type%','.*');
    add_rewrite_rule('type/(.*)[/]?$''index.php?post_type=$matches[1]''top');
    }
    add_action('init''post_type_add_custom_urls'); 
    If I wanted to then hook those to a custom template, like custom.php, I could do this:

    PHP Code:
    function post_type_add_template() {
     
    $post_type get_query_var('post_type');
     if (!empty(
    $post_type)) {
      
    locate_template(array("{$post_type}.php","index.php"), true);
      exit;
     }
    }
    add_action('template_redirect''post_type_add_template'); 

  7. #7
    lag47 is offline Hello World
    Join Date
    Apr 2010
    Location
    the Top Right Side of the United States
    Posts
    5

    Default how about /%taxonomy%/%postname%/ for permalinks

    How would you do how about /%taxonomy%/%postname%/ for permalinks

  8. #8
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    Anything further on this? I'm wondering if there's a way to use custom post types, and then be able to pick specific page templates (just used for the custom post types).

    Any ideas? Possible? Too much work?

  9. #9
    hakre's Avatar
    hakre is offline Here For The Peanuts
    Join Date
    Jun 2010
    Posts
    129

    Default

    From what I can see (trunk), there's a lookup for the post-type:

    PHP Code:
    'single-' $object->post_type '.php' 
    in function get_single_template()

    a file match in either theme or sub-theme should make it then.

    additionally, you could hook into single_template to override file names (full path).
    hakre on wordpress (clicking this all three minutes help to keep the cache fresh - thanks)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •