所以我尝试为WordPress制作一个简单的插件。就像一篇评论。甚至试图通过TutsPlus的教程来做到这一点。每次尝试时我都会得到404。然后我从导师那里拿到了代码,在查看我的评论帖子类型帖子时仍然得到了404分。
function my_custom_posttypes() {
$labels = array(
\'name\' => \'Testimonials\',
\'singular_name\' => \'Testimonial\',
\'menu_name\' => \'Testimonials\',
\'name_admin_bar\' => \'Testimonial\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Testimonial\',
\'new_item\' => \'New Testimonial\',
\'edit_item\' => \'Edit Testimonial\',
\'view_item\' => \'View Testimonial\',
\'all_items\' => \'All Testimonials\',
\'search_items\' => \'Search Testimonials\',
\'parent_item_colon\' => \'Parent Testimonials:\',
\'not_found\' => \'No testimonials found.\',
\'not_found_in_trash\' => \'No testimonials found in Trash.\',
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_icon\' => \'dashicons-id-alt\',
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'testimonials\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' )
);
register_post_type( \'testimonial\', $args );
}
add_action( \'init\', \'my_custom_posttypes\' );
// Flush rewrite rules to add "review" as a permalink slug
function my_rewrite_flush() {
my_custom_posttypes();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'my_rewrite_flush\' );
最上面是php开始标记和插件信息(和往常一样)。尝试了几个主题-仍然得到404。每次测试之前,我都会在Permalinks上保存更改并停用&&;激活了该插件。
有人有什么想法吗?我现在正在学习(昨天开始)。