Custom single page for custom post type, wordpress

ajmajmajma picture ajmajmajma · Feb 24, 2014 · Viewed 32k times · Source

I've just figured out how to make custom post types and feed them out onto a page, I am wondering if I can change the single post pages for them?

Can I just set up a single-news.php for example? If so, how would that PHP file be formatted and how does WordPress know to use that single-news.php file? I'm just looking to have them spit out the full article.

Thank you!!

Answer

Fred K picture Fred K · Aug 27, 2014

After you created the CPT, do this for showing single posts of your CPT:

  • Duplicate the single.php file in your template and rename it like single-{post_type}.php (eg. single-movie.php)
  • Flush the permalinks from WordPress

You can get more details from this post

  • Now if you want to show a list of CPT you can use get_posts() with args:

    $args = array( ... 'post_type' => 'movie' )