手头的问题:
我在wordpress中有自定义类别,名为"产品类别"自定义帖子类型"产品"。
我想从
更改网址somesite.com/product/airconditioner/voltas/productname
到
somesite.com/airconditioner/voltas/productname
注册帖子和类别的代码
class aw_products_post_type {
function __construct(){
$this->aw_register_post_type();
$this->aw_add_post_type_actions();
$this->aw_add_post_type_filters();
}
public function aw_register_post_type(){
// Labels
$labels = array(
'name' => __('Products','framework'),
'singular_name' => __('Product','framework'),
'add_new' => __('Add new','framework'),
'add_new_item' => __('Add new product','framework'),
'edit_item' => __('Edit','framework'),
'new_item' => __('New product','framework'),
'view_item' => __('View product','framework'),
'search_items' => __('Search product','framework'),
'not_found' => __('No product found','framework'),
'not_found_in_trash' => __('No product found in trash','framework'),
'parent_item_colon' => '',
'menu_name' => __('Products','framework')
);
$short_url = (get_option('tz_products_short_url') != '') ? get_option('tz_products_short_url') : 0;
$slug_first_part = ((get_option('tz_custom_products_slug') != '') ? get_option('tz_custom_products_slug') : 'product');
if($short_url == 1) {
$slug = $slug_first_part;
} else {
$slug = $slug_first_part."/%product_category%/%product_brand%";
}
// Arguments
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri().'/img/admin/admin-products.png',
'rewrite' => true,
'capability_type' => 'post',
'rewrite' => array("slug" => $slug), // Permalinks format
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('post_tag'),
'supports' => array('title','editor','author','thumbnail','excerpt', 'comments', 'tags')
);
解决方案在.htaccess
中尝试过<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^product/(.*)$ /$1 [L,NC,R]
</IfModule>
此解决方案无效。 更新:上述解决方案导致错误&#34;重定向太多&#34;
我也试过删除&#39;产品&#39;来自
$slug_first_part = ((get_option('tz_custom_products_slug') != '') ? get_option('tz_custom_products_slug') : 'product');
此行引用上面给出的代码来注册自定义帖子类型。
如果这个问题很容易,请尝试回答它,不要点击下拉按钮。
答案 0 :(得分:0)
所以没有人回答这个问题,这是解决方案
$slug = $slug_first_part."/%product_category%/%product_brand%";
删除了这个$ slug_first_part。从上面的代码。