我是wordPress的新手,我正在一个产品類別丰富的網站上工作。 我想建立一个自定義帖子型別来添加一堆产品.我將展示我要實現的目標,然後详细說明我所遇到的問题。
Here are my requirements:
- 我需要按
brand
分類我的产品 和functionality
並且需要將其翻译為:
by brand:
example.com/products/sub-category/product-name
eg. domain.com/products/toshiba/toshiba-E-Studio-2518A
by functionality:
example.com/products/functionality-category/product-name
eg. domain.com/products/color-printer/toshiba-E-Studio-2518A
如您在上面的示例中看到的那樣,产品归為多个類別。
- 我需要所有這些類別和分類法都有一个存档頁面(或包含所有相關帖子的任何頁面)
eg. domain.com/products/toshiba/ -> show all toshiba products
eg. domain.com/products/color-printer/ -> show all color printers
eg. domain.com/products/ -> show all products
到目前為止我已经尝試過:
- First I tried creating it using
CPT ui
,我在自定義帖子中使用了類別,它解決了50%的問题.但是類別的URL鏈接不能与自定義帖子鏈接相同。 - 我建立了一个插件,因此可以拥有更多控製權,但仍然没有運气。遵循了這篇文章,說實话
對於這个問题,我很难過 現在並且真的找不到解決方案,因此,我希望获得一些帮助。
谢谢
week最新回復
- 6月前1 #
相似問題
- wordpress:自定義帖子型別,類別分開wordpresscustomposttypeswordpresscustomtaxonomy2020-11-27 11:52
- wordpress:可以將自定義分類法命名為"類別"吗?wordpresscustomposttypeswordpresscustomtaxonomy2020-06-09 00:56
- wordpress:如何在單个自定義帖子上获取get_term_meta?wordpresscustomposttypeswordpresscustomtaxonomywordpresscustomfieldwordpresstemplateswordpressadvancedtaxonomyqueries2020-06-12 11:56
- wordpress:想要仅過濾管理區域中的父帖子wordpresscustomposttypeswordpresswpquerywordpresscustomtaxonomywordpressfilterswordpresswpdb2020-06-20 22:27
- wordpress:過濾自定義帖子型別以查詢父帖子wordpresscustomposttypeswordpresscustomtaxonomywordpressfilterswordpresswpdbwordpresstextdomain2020-06-20 23:27
欢迎使用wPSE。
這可以很直接地解決。
註册自定義帖子型別 products
為您的自定義帖子型別註册两个分類法(品牌和功能)
遵循模板層次結構和wordPress標準,為wordPress提供正確的模板
清除您的重寫規則(不能跳過,但是很容易)
Step 1
<?php /* Register Custom Post Type 'products' */ function wpse_register_custom_post_type_products(){ // Custom Post Type Name $cpt_name = 'products'; // CPT Features // the fields you need $cpt_features = array( 'title', 'excerpt', 'revisions', 'thumbnail' ); // Slug / name of the archive /product/my-product/ $cpt_slug = 'products'; $labels = array( 'name' => __('Products', 'textdomain'), 'singular_name' => __('Product', 'textdomain'), 'menu_name' => __('Products', 'textdomain'), 'name_admin_bar' => __('Products', 'textdomain'), // Archive page name 'all_items' => __('Products', 'textdomain'), 'add_name' => __('Add new products', 'textdomain'), 'add_new_item' => __('Add new products', 'textdomain'), 'edit' => __('Edit products', 'textdomain'), 'edit_item' => __('Edit product', 'textdomain'), 'new_item' => __('New product', 'textdomain'), 'view' => __('View products', 'textdomain'), 'view_item' => __('View product', 'textdomain'), 'search_items' => __('Search products', 'textdomain'), 'parent' => __('Parent product', 'textdomain'), 'not_found' => __('No product found', 'textdomain'), 'not_found_in_trash' => __('No product found in trash', 'textdomain') ); /* ------------------------------------------ End of Edit */ $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'show_in_rest' => true, 'menu_position' => 21, 'menu_icon' => 'dashicons-marker', // Dashicon 'can_export' => true, 'delete_with_user' => false, 'hierarchical' => false, 'has_archive' => true, 'query_var' => true, 'capability_type' => 'post', 'map_meta_cap' => true, // 'capabilities' => array(), 'rewrite' => array( 'slug' => $cpt_slug, 'with_front'=> true, 'pages' => true, 'feeds' => false ), 'supports' => $cpt_features ); register_post_type($cpt_name, $args); } add_action('init', 'wpse_register_custom_post_type_products', 21); ?>