在後台,建立一個新的post_type function create_post_type() { $hk_labels = array( 'name' => 'Hong Kong Posts', 'singular_name' => 'Hong Kong Post', 'add_new' => 'Add New', 'add_new_item' => 'Add New Hong Kong Post', 'edit_item' => 'Edit Hong Kong Post', 'new_item' => 'New Hong Kong Post', 'all_items' => 'All Hong Kong Posts', 'view_item' => 'View Hong Kong Post', 'search_items' => 'Search Hong Kong Post', 'not_found' => 'No Hong Kong Post', 'not_found_in_trash' => 'No Hong Kong Post found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Hong Kong' ); $hk_args = array( 'labels' => $hk_labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'hk','with_front'=>true ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => true, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'author', 'revisions' ), 'taxonomies' => array('post_tag') ); register_post_type( 'hk', $hk_args ); } add_action( 'init', 'create_post_type' ); register_post_type( 'hk', $hk_args ); 其中,'hk',就是你的網址了 http://127.0.0.1/hk/ 網址如果這樣不能連 你要去後台的Permalink 設定為「custom structure」 http://127.0.0.1/wp3.6.1/ 「/%post_id%/」 http://127.0.0.1/wp3.6.1/hk/test1/ 然後你去發表一篇文章,就可以瀏覽了 至於檔案的對應 它就是 archive-hk.php single-hk.php 或者是 ?post_type=hk&xxx 這裡它有講到 Template Files In the same way single posts and their archives can be displayed using the single.php and archive.php template files, respectively, single posts of a custom post type will use single-{post_type}.php and their archives will use archive-{post_type}.php and if you don't have this post type archive page you can pass BLOG_URL?post_type={post_type}
文章標籤
全站熱搜
創作者介紹
創作者 Vera維拉 的頭像
Vera維拉

生活好創意

Vera維拉 發表在 痞客邦 留言(0) 人氣(148)