Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to make my custom post type display on the front end as if it were a page. Depending on the theme, it won't have the date, author, etc...

I've looked into creating a template such as 'single-<CPT>.php'. But that's too static to work for any theme design.

Is it possible to somehow tell the current theme to display the custom post type in the same way it would display a normal page.

Thanks!

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

There are a number of template filters you can use to alter the template hierarchy. Have a look at the template hierarchy page at the filters and example provided.

Here's a modified version of the example that uses single_template. It checks for a specific custom post type and loads the theme's page.php template if it exists:

function wpa54721_single_template( $templates = '' ){

    // get data for the current post and check type
    $this_post = get_queried_object();
    if( 'my_custom_post_type' == $this_post->post_type ):

        // $templates could be empty, a string, or an array,
        // we need to check and alter it appropriately

        if( !is_array( $templates ) && !empty( $templates ) ):
            // it's a string
            $templates = locate_template( array( 'page.php', $templates ), false );
        elseif( empty( $templates ) ):
            // it's empty
            $templates = locate_template( 'page.php', false );
        else:
            // it's an array
            $new_template = locate_template( array( 'page.php' ) );
            if( !empty( $new_template ) ) array_unshift( $templates, $new_template );
        endif;

    endif;

    return $templates;
}
add_filter( 'single_template', 'wpa54721_single_template' );
share|improve this answer
    
This works perfectly, thanks for your help! –  Sarathi J. Hansen Jun 10 '12 at 1:10
add comment

This is something I have to deal with every day when creating themes that use lots of custom post types.

Basically, we want our custom post types to have all the same features as a regular post or page. This means categories, archives, etc.

First you should make all of your regular pages. This means:

  • archive-cpt.php
  • categories-cpt.php
  • single-cpt.php
  • etc..

Now, if you have done it right, navigating to pages like /custom-post-type/page/2/ you should see you archive, and etc.

Now, the trick after this is to make the users see your custom post type on the front page instead of the regular blog posts.

To do that you'll want to create a page template. This page template will end up working like index.php or archive.php, where it will list 10 (or more) posts. When you've created it, create a new page on the site and set the page template to your new template.

After that, go into Settings -> Reading and select that page as your Front Page. You should now have a list of the most recent custom posts you've added.

share|improve this answer
    
I'm actually not looking to list multiple items of a custom post type, but rather when the user is viewing one, /post-type/permalink/ it will display not as a post, with the date and author, but as a page with just the title and content. –  Sarathi J. Hansen Jun 10 '12 at 1:04
    
You could filter out the author/date, however some theme designs are very dependent on that. If you aren't providing the theme design, there isn't a ton you can do. –  Tyler Carter Jun 10 '12 at 1:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.