Is it mandatory to create single post page for each of the custom post types?不,不是全部。如果添加“public\\u queryable”=>false;系统不会为您的CPT创建单页条目。(确保在此更改后刷新永久链接)
If not, then what about the ‘href’ attribute value(where we write this code the_permalink()) of the anchor tag ()? Should I keep it dead like href=”#”?当public\\u queryable arg设置为false时,这将只加载到主页
Is it mandatory to design Section Page, Portfolio Page etc. which are created by custom page templates? 不,不是。事实上,如果您将“has\\u archive”=>设置为false;这些页面也不会加载,如果有人试图转到那些存档页面“www.example.com/your\\cpt”,它也会加载到主页。(进行此更改后,请记住刷新永久链接)
Is it mandatory to keep ‘has_archive’ => true in the custom post register? 否。请参阅以上问题的答案。
冲洗你的永久性皮肤。转到仪表板,然后单击设置/永久链接并单击保存。
或者,您可以将其添加到插件中。但此调用只应作为初始化的一部分进行,因为它确实使用了大量资源。您可以这样做:
function my_rewrite_flush() {
// First, we "add" the custom post type via the above written function.
// Note: "add" is written with quotes, as CPTs don\'t get added to the DB,
// They are only referenced in the post_type column with a post entry,
// when you add a post of this CPT.
my_cpt_init();
// ATTENTION: This is *only* done during plugin activation hook in this example!
// You should *NEVER EVER* do this on every page load!!
flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'my_rewrite_flush\' );
这里还有更多信息:
https://codex.wordpress.org/Function_Reference/register_post_type