custom post type loop template override
-
I have a registered post type “portfolio.” The loop/index page for recent portfolio posts loaded by default by loading “portfolio” as the page, example: mysite.com/portfolio (my permalinks are set to page name).
This page loads a default post template with the portfolio posts in place. No matter what I do, I can’t make mysite.com/portfolio use a different template. I would like to for it to use portfolio.php in my child theme, but it does not load that code, but instead uses the blog template no matter what
My registering the CPT in functions.php of child theme:
add_action( ‘init’, ‘portfolio_init’ );
/**
* Register a portfolio post type.
*
* @link http://codex.ww.wp.xz.cn/Function_Reference/register_post_type
*/
function portfolio_init() {
$labels = array(
‘name’ => _x( ‘Portfolio’, ‘post type general name’, ‘your-plugin-textdomain’ ),
‘singular_name’ => _x( ‘Portfolio Item’, ‘post type singular name’, ‘your-plugin-textdomain’ ),
‘menu_name’ => _x( ‘Portfolio’, ‘admin menu’, ‘your-plugin-textdomain’ ),
‘name_admin_bar’ => _x( ‘Portfolio Item’, ‘add new on admin bar’, ‘your-plugin-textdomain’ ),
‘add_new’ => _x( ‘Add New’, ‘portfolio’, ‘your-plugin-textdomain’ ),
‘add_new_item’ => __( ‘Add New Portfolio Item’, ‘your-plugin-textdomain’ ),
‘new_item’ => __( ‘New Portfolio Item’, ‘your-plugin-textdomain’ ),
‘edit_item’ => __( ‘Edit Portfolio Item’, ‘your-plugin-textdomain’ ),
‘view_item’ => __( ‘View Portfolio Item’, ‘your-plugin-textdomain’ ),
‘all_items’ => __( ‘All Portfolio Items’, ‘your-plugin-textdomain’ ),
‘search_items’ => __( ‘Search Portfolio Items’, ‘your-plugin-textdomain’ ),
‘parent_item_colon’ => __( ‘Parent Portfolio Items:’, ‘your-plugin-textdomain’ ),
‘not_found’ => __( ‘No portfolio items found.’, ‘your-plugin-textdomain’ ),
‘not_found_in_trash’ => __( ‘No portfolio items found in Trash.’, ‘your-plugin-textdomain’ )
);$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘portfolio’ ),
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘comments’ )
);register_post_type( ‘portfolio’, $args );
}
The topic ‘custom post type loop template override’ is closed to new replies.