• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

Using A Page Template File For Single Custom Post Types

If for some reason you don’t want to use a default single post template for your custom post type, you can use a page.php file instead.

On top of this you can also add support for Page Attributes to the code in your functions file which registers your CPT.

The downside of copying your parent themes page.php file to your child theme and renaming it single-cpt.php, is you may lose pagination.

Single CPT Page File

For themes which include get_template_part(), you can simply use this code in your single-cpt.php file rather than all the standard code included in a page.php file.

get_template_part( 'page' );

Pretty cool when you only have one line of code in a template. Just one of the many benefits of using get_template_part() for coding/resource efficiency.

Add Page Attributes To Custom Post Types

This is the line of code you can add to the code you use in your functions file to register your custom post type.

'supports' => array(  'page-attributes' ),

Standard stuff in Genesis but many non Genesis users don’t add this to their code for some reason maybe because they simply don’t know about it.

Add Pagination To Single Custom Post Types

If you need to add pagination to a your single cpt’s, this code may help depending on which theme you’re using.

My opinion is to use a single post file for this as you can easily add page attributes anyway and retain built in pagination.

Custom Post Type

Reader Interactions

Comments

  1. Herb Trevathan says

    March 6, 2014 at 9:47 pm

    Awesome! Thank You : )

    Log in to Reply
    • Brad Dalton says

      March 7, 2014 at 4:44 am

      No worries Herb

      Not sure why a page template is better than a single post template for this purpose but i guess there must be a reason as posts always seem more flexible than pages and you can add page attributes anyways.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags