I Registered a New CPT , and it did works but , after working on something different , when i refreshed the page , i realized that my CPT turn to work with index.php . i think all is fine with my code . here it is .
function mn_portfolio_post_type_init() {
$labels = array(
// Labels .
);
$portfolioargs = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'query_var' => true,
'publicly_queryable' => true,
'rewrite' => true,
'supports' => array(
'title',
'editor',
'thumbnail',
'author',
'excerpt',
'custom-fields',
'revisions'
),
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-media-document',
'capability_type' => 'post'
);
register_post_type('portfolio', $portfolioargs);
}
add_action('init', 'mn_portfolio_post_type_init');
After That I Used a new page-name.php to work with , and all was fine , but for now i'm out of ideas for help me out of that .
I Registered a New CPT , and it did works but , after working on something different , when i refreshed the page , i realized that my CPT turn to work with index.php . i think all is fine with my code . here it is .
function mn_portfolio_post_type_init() {
$labels = array(
// Labels .
);
$portfolioargs = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'query_var' => true,
'publicly_queryable' => true,
'rewrite' => true,
'supports' => array(
'title',
'editor',
'thumbnail',
'author',
'excerpt',
'custom-fields',
'revisions'
),
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-media-document',
'capability_type' => 'post'
);
register_post_type('portfolio', $portfolioargs);
}
add_action('init', 'mn_portfolio_post_type_init');
After That I Used a new page-name.php to work with , and all was fine , but for now i'm out of ideas for help me out of that .
It looks like your theme is missing certain key files that are needed in order to keep WordPress from defaulting to index.php
per the WordPress Template Hierarchy.
Since you have defined your portfolio
post type to act like posts by setting 'hierarchical'
to false
, you should probably be using the post custom template files.
In reading the chart from left to right, you want to create one, possible two files depending if you want the index view to be custom as well as the single post view. For the single view, WordPress uses single-$posttype.php
where $posttype
is replaced by the slug you gave your custom post type. In your case this file would be single-portfolio.php
. The archive page is a similar naming convention with archive-$posttype.php
so you would make archive-portfolio.php
Pages do not have support for this. With a page you can pretty much only use page-$id.php
or page-$slug.php
.