• Resolved csjWP

    (@csjwp)


    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.php and rename it to single-portfolio.php. Samething with content.php in my template-parts folder, rename it to content-portfolio.php. And link to it from single-portfolio.php

    get_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.php it 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, @csjwp. The post type which you actually registered is cubo_portfolio, so your single-portfolio.php file would need to be named single-cubo_portfolio.php instead.

    (And while you could keep the template part file’s name as content-portfolio.php if you want, I recommend changing it to content-cubo_portfolio.php instead, just for the sake of consistency.)

    Thread Starter csjWP

    (@csjwp)

    OMG! WOW, I’m speechless. Sometimes I just can’t see what is under my nose.

    But thank you so much @girlieworks I really appreciate it.

    You’re welcome, @csjwp! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘single-cpt.php and content-cpt.php aren't taking affect over single.php’ is closed to new replies.