1

I thought we can apply templates to custom page types:

You can't apply templates to custom post types in this manner. That will show up only if the post type is 'page'

My code:

function keyword_pages_init() {
    $args = array(
      'label' => 'Keywords',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'page',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'keywords'),
        'query_var' => true,
        'menu_icon' => 'dashicons-admin-page',
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'trackbacks',
            'custom-fields',
            'comments',
            'revisions',
            'thumbnail',
            'author',
            'page-attributes',
            )
        );
    register_post_type( 'keywords', $args );
}
add_action( 'init', 'keyword_pages_init' );

But the template is not shown up under page attributes at all when I try to add a new page under this custom page type.

Any ideas?

  • You can use custom post templates, I posted an example here. – birgire Apr 3 '17 at 15:09
2

Are you referring to the new Post Type Templates feature included in 4.7?

To make a page template available to your 'keywords' cpt you'll want to add a header like this to a custom page template.

/**
 * Template Name: Template Name
 * Template Post Type: post, page, keywords
 */

This template would be available to all posts, pages, and your keywords cpt. Here is an example of a full page template...

<?php
/**
 * ACF Flexible Content template
 *
 * Learn more: https://codex.wordpress.org/Template_Hierarchy
 *
 * @package YM
 * @since   1.0
 * @version 1.0
 */

/**
 * Template Name: Flexible Content
 * Template Post Type: post, page, product, event
 */



/**
 * Add landing page body class to the head
 *
 * @param $classes
 * @return array
 */
add_filter( 'body_class', function ( $classes ) {
    $classes[] = 'flexible-content-template';
    return $classes;
} );



/**
 * Remove entry header
 */
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );



/**
 * Force full width layout
 */
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );



/**
 * Remove breadcrumbs
 */
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );



/**
 * Add ACF Flexible Content. See inc/layout.php
 *
 * @uses ym_flexible_content();
 */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_after_header', 'ym_flexible_content' );



genesis();

https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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