0

私は、プラグインを介して "製品"と呼ばれるカスタムポストタイプを作成したWordpress 3ウェブサイトを設定しようとしています。このカスタムポストタイプに加えて、カスタム分類を作成して、ブログカテゴリに干渉することなく商品をカテゴリに配置できるようにしました。これはAdminシステムを通じてすばらしい結果を出しています。ここまでは順調ですね。Wordpressカスタムポストタイプ、カスタム分類、URLとテーマ

問題は、製品とカテゴリにアクセスするときに発生します。理想的には次のURL構造を持っています:

/products - すべてのカテゴリのページを表示します。

/products/category - 指定した 'カテゴリ'で割り当てられたすべての商品を表示します。

/products/product - 単一の製品を表示します。

私は過去数日間さまざまな情報源から読んできましたが、私が探している情報は非常に断片化しているようで、問題については非常に混乱していました。 Wordpressの文脈の中で。

私が非常に混乱しているのは、上記の例で示したURLがテーマエンジンとどのように結びついているかです。私はどのテンプレートを作成すべきか、この作業をするためにどのフックを結びつけるべきかを十分に理解していません。

したがって、基本的な質問は次のとおりです。カスタムの投稿タイプとカスタム分類を正しいテーマテンプレートに対応させるにはどうすればよいですか?

答えて

1

私は、これは古い質問です知っているが、これは、あなたがregister_post_typeregister_taxonomy WordPressの機能を使用する必要があります後にあなたがしているものを達成するために他の誰か...

を助けるかもしれません。

あなたは、すべてのオプションを扱うときあなたの人生を容易にするためにhttp://generatewp.com/post-type/のようなカスタムポスト・ジェネレータを使用することができます

// Register Custom Post Type 
function products() { 
    $labels = array(
     'name'    => 'Products', 
     'singular_name'  => 'Product', 
     'menu_name'   => 'Product', 
     'parent_item_colon' => 'Parent Product:', 
     'all_items'   => 'All Products', 
     'view_item'   => 'View Product', 
     'add_new_item'  => 'Add New Product', 
     'add_new'    => 'New Product', 
     'edit_item'   => 'Edit Product', 
     'update_item'   => 'Update Product', 
     'search_items'  => 'Search products', 
     'not_found'   => 'No products found', 
     'not_found_in_trash' => 'No products found in Trash' 
    ); 
    $args = array(
     'label'    => 'product', 
     'description'   => 'Product information pages', 
     'labels'    => $labels, 
     'supports'   => array('title', 'editor', 'excerpt',), 
     'taxonomies'   => array('category'), 
     'hierarchical'  => false, 
     'public'    => true, 
     'show_ui'    => true, 
     'show_in_menu'  => true, 
     'show_in_nav_menus' => true, 
     'show_in_admin_bar' => true, 
     'menu_position'  => 5, 
     'menu_icon'   => '', 
     'can_export'   => true, 
     'has_archive'   => true, 
     'exclude_from_search' => false, 
     'publicly_queryable' => true, 
     'capability_type'  => 'post' 
    ); 
    register_post_type('product', $args); 
} 
// Hook into the 'init' action 
add_action('init', 'products', 0); 

// Register Custom Taxonomy 
function product-category() { 
    $labels = array(
     'name'      => 'Product Category', 
     'singular_name'    => 'Product Categories', 
     'menu_name'     => 'Product Category', 
     'all_items'     => 'All Product Categories', 
     'parent_item'    => 'Parent Product Category', 
     'parent_item_colon'   => 'Parent Product Category:', 
     'new_item_name'    => 'New Product Category Name', 
     'add_new_item'    => 'Add New Product Category', 
     'edit_item'     => 'Edit Product Category', 
     'update_item'    => 'Update Product Category', 
     'separate_items_with_commas' => 'Separate product categories with commas', 
     'search_items'    => 'Search product categories', 
     'add_or_remove_items'  => 'Add or remove product categories', 
     'choose_from_most_used'  => 'Choose from the most used product categories', 
    ); 
    $rewrite = array(
     'slug'      => 'product-category', 
     'with_front'     => true, 
     'hierarchical'    => true, 
    ); 
    $args = array(
     'labels'      => $labels, 
     'hierarchical'    => false, 
     'public'      => true, 
     'show_ui'     => true, 
     'show_admin_column'   => true, 
     'show_in_nav_menus'   => true, 
     'show_tagcloud'    => true, 
     'query_var'     => 'product-category', 
     'rewrite'     => $rewrite, 
    ); 
    register_taxonomy('product-category', 'product', $args); 

} 
// Hook into the 'init' action 
add_action('init', 'product-category', 0); 

あなたのfunctions.phpファイルに次のようなものが必要でしょう。

このコードを追加した後、またはURL構造を修正した後に、カスタムの投稿タイプとタクソノミーを登録してDNSルールを消去することが重要です。これを行うには、WordPressの管理者設定 - >固定リンクページにアクセスしてください。自動的にDNSルールがフラッシュされます。

編集表示されるテンプレートを制御するために、あなたのテーマフォルダ内の以下のファイル:

  • アーカイブ-product.php
  • 分類-製品category.php
  • シングルproduct.php
関連する問題