0
我決定創建一個插件(因爲我的主題很可能會在未來發生變化),而不是將我的自定義帖子類型放入我的主題中。WordPress的自定義帖子類型插件 - 我哪裏錯了?
我創建了一個文件夾,我的插件,並與喜歡的內容做了一個文件(myplugin.php):
<?php
/*
Plugin Name: myplugin
Plugin URI: http://www.mywebsite.com
Description: Custom post types for my website
Version: 1.0
Author: my name
Author URI: http://www.mywebsite.com
License: Private
*/
?>
而且加入我的自定義後類型到functions.php文件,像這樣:
<?php
add_action('init', 'register_cpt_portfolio');
function register_cpt_portfolio() {
$labels = array(
'name' => _x('Portfolio', 'portfolio'),
'singular_name' => _x('Portfolio', 'portfolio'),
'add_new' => _x('Add New', 'portfolio'),
'add_new_item' => _x('Add New Portfolio', 'portfolio'),
'edit_item' => _x('Edit Portfolio', 'portfolio'),
'new_item' => _x('New Portfolio', 'portfolio'),
'view_item' => _x('View Portfolio', 'portfolio'),
'search_items' => _x('Search Portfolio', 'portfolio'),
'not_found' => _x('No portfolio found', 'portfolio'),
'not_found_in_trash' => _x('No portfolio found in Trash', 'portfolio'),
'parent_item_colon' => _x('Parent Portfolio:', 'portfolio'),
'menu_name' => _x('Portfolio', 'portfolio'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'To display completed works.',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields'),
'taxonomies' => array('category'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'page'
);
register_post_type('portfolio', $args);
}
?>
但是,在激活插件後,我看不到我的自定義帖子類型 - 我錯過了這裏的任何步驟嗎?謝謝你的幫助!