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 .
Share Improve this question edited Feb 15, 2019 at 22:59 Simo Patrek asked Jan 13, 2018 at 23:38 Simo PatrekSimo Patrek 1121 gold badge4 silver badges15 bronze badges 10- 1 I would suggest moving it to a plugin file since you're changing how data is structured. What template file do you want it to use? – Cedon Commented Jan 13, 2018 at 23:46
- thanks man for responding , but i'm doing it in functions.php – Simo Patrek Commented Jan 13, 2018 at 23:47
- What template file do you want this post type to use to show content? – Cedon Commented Jan 13, 2018 at 23:48
- i'm not sure what you wanna tell me ? – Simo Patrek Commented Jan 13, 2018 at 23:48
- 1 have you seen developer.wordpress/themes/basics/template-hierarchy/… and developer.wordpress/themes/basics/template-hierarchy/… ? – Michael Commented Jan 13, 2018 at 23:59
1 Answer
Reset to default 1It 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
.