所以我的WordPress CMS已經很長的路要走(和我學到了不少關於WordPress的。我已經創建了一個自定義後類型,稱爲Products
這是在這裏:過濾器,並通過他們的自定義分類查詢我的產品(自定義後型)
add_action('init', 'create_product_post_type');
function create_product_post_type()
{
$labels = array(
'name' => _x('Products', 'post type general name'),
'singular_name' => _x('Product', 'post type singular name'),
'add_new' => _x('Add New', 'product'),
'add_new_item' => __('Add New Product'),
'edit_item' => __('Edit Product'),
'new_item' => __('New Product'),
'view_item' => __('View Product'),
'search_item' => __('Search Products'),
'not_found' => __('No products found'),
'not_found_in_trash' => __('No products found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Products'
);
$args = array(
'label' => __('Products'),
'labels' => $labels,
'public' => true,
'can_export' => true,
'show_ui' => true,
'_builtin' => false,
'capability_type' => 'post',
'menu_icon' => get_bloginfo('template_url').'/functions/images/product.png',
'hierarchical' => false,
'rewrite' => array("slug" => "product"),
'supports' => array('title'), //MAYBE add thumbnail later!
'show_in_nav_menus' => true
);
register_post_type('product', $args);
}
然後叫Category
一個自定義分類這是在這裏:。
function create_productcategory_taxonomy() {
$labels = array(
'name' => _x('Categories', 'taxonomy general name'),
'singular_name' =>_x('Category', 'taxonomy singular name'),
'search_items' => __('Search Categories'),
'popular_items' => __('Popular Categories'),
'all_items' => __('All Categories'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Edit Product Category'),
'update_item' => __('Update Product Category'),
'add_new_item' => __('Add New Product Category'),
'new_item_name' => __('New Product Category'),
'separate_items_with_commas' => __('Separate categories with commas'),
'add_or_remove_items' => __('Add or remove product categories'),
'choose_from_most_used' => __('Choose from the most used categories')
);
register_taxonomy('productcategory', 'product', array (
'label' => __('Product Category'),
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'product-category'),
));
}
我在可溼性粉劑管理員菜單中調用的產品,有我做了一個自定義模板創建一個單頁去http://localhost/project/products帶來它和它sts所有產品帖子類型。我還爲single-products.php製作了一個頁面,該頁面顯示單個產品帖子類型的詳細信息。
我不知道如何做的是創造一種由自定義分類Category
,上面是過濾我的產品。假設我有一個產品是一個Widget。這個小工具有'彈簧加載'Category
。如果我想查看單個小部件,我可以鏈接到http://localhost/project/products/widget,它會調出single-product.php
頁面,並在我爲此頁面設置格式時顯示小部件。但我想鏈接到「彈簧加載」類別,並將所有產品列在該自定義類別中。我相信每個類別都有它自己的彈子(例如彈簧加載)。如果我去http://localhost/project/product-category/spring-loaded它會彈出一個頁面,但我不知道它正在加載哪個文件,其他方面我可以修改輸出。現在它將每個產品加載爲普通帖子(包含日期,評論等)。
所以我的問題是如何過濾這些類別?或者我修改哪個文件以更改從http://localhost/project/product-category/spring-loaded鏈接的頁面的輸出?
我希望這是有道理的。謝謝!
UPDATE: AHHHH。現在是有道理的。我改變了這一點:
register_taxonomy('productcategory', 'product', array (
'hierarchical' => true,
'rewrite' => array('slug' => 'product-category'),
));
這樣:
register_taxonomy('productcategory', 'product', array (
'hierarchical' => true,
'rewrite' => array('hierarchical' => true),
));
雖然我不知道它正是這麼做。
我還創建了一個分類,productcategory.php並做了一些快速格式化和測試,但它確實工作。我可以去http://localhost/project/productcategory/,它會列出該類別的所有產品。
現在我需要改變我重寫規則是你一個人?我真的不明白htaccess是如何工作的,所以我不知道我是否需要改變它。謝謝!
,如果它工作,那麼你不必改變你的重寫。 – ariefbayu 2011-06-09 23:24:19