single-cpt.php and content-cpt.php aren't taking affect over single.php
-
Hi all,
I must have stared myself blind. I know I’ve done this before, but now it isn’t working and I can’t tell why. It seems by the book to me… (But it is not!)I’ve created a custom post type. And it shows up in the dashboard, and I’ve added some dummy text and saved my permalinks. Test viewed the post, it works and the slug is right. (Apologies some of the $labels and $args text is in Danish).
/*----------------------------------------------------------------------------*/ /* Custom Post Types and Taxonomies */ /*----------------------------------------------------------------------------*/ /** * cubo_portfolio Post Type */ class cubo_portfolio { function cubo_portfolio() { add_action('init',array($this,'create_post_type')); } function create_post_type() { $labels = array( 'name' => 'Portfolio', 'singular_name' => 'Portfolio', 'add_new' => 'Tilføj nyt', 'all_items' => 'Alle projekter', 'add_new_item' => 'Tilføj nyt projekt', 'edit_item' => 'Rediger projekt', 'new_item' => 'Nyt portfolio projekt', 'view_item' => 'Vis projekt', 'search_items' => 'Søg projekter', 'not_found' => 'Ingen projekter fundet', 'not_found_in_trash' => 'Ingen projekter fundet i papirkurven', 'parent_item_colon' => 'Forælder post:', 'menu_name' => 'Portfolio' ); $args = array( 'labels' => $labels, 'description' => "Alle projekter og byggerier", 'public' => true, 'exclude_from_search' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-portfolio', 'capability_type' => 'post', 'hierarchical' => false, 'supports' => array('title','editor','thumbnail'), 'has_archive' => true, 'rewrite' => array('slug' => 'portfolio', 'with_front' => 'before-portfolio'), 'query_var' => true, 'can_export' => true ); register_post_type('cubo_portfolio',$args); } } $cubo_portfolio = new cubo_portfolio();Next step too make a duplicate of
single.phpand rename it tosingle-portfolio.php. Samething withcontent.phpin my template-parts folder, rename it tocontent-portfolio.php. And link to it fromsingle-portfolio.phpget_template_part( 'template-parts/content', 'portfolio', get_post_format() );But when I just try and echo out some random text to test that it is working. Nothing is showing up, but if I echo out the text in
single.phpit shows.So I’m not targeting my new .php files. And I can’t spot the mistake, since I’m using the ‘slug’ I declared when registering the post type.
Can anyone spot the mistake? Thanks for the help.
The topic ‘single-cpt.php and content-cpt.php aren't taking affect over single.php’ is closed to new replies.