如何将固定链接更改为分类和帖子类型

时间:2014-09-28 作者:Burak Şahin

你好,我想更改我的分类法并发布permalink。我有这样的分类法;

宝马1系问题1)如何更改永久链接taxonomy

网站。com/brand/audi网站。com/brand/audi/a1网站。com/brand/audi/a1/14 tfsi网站。com/品牌/奥迪/a1/16 tdi网站。com/brand/bmw网站。com/brand/bmw/1系网站。com/brand/bmw/1系/115d问题2)如何更改permalinkposts

网站。com/bmw/1-series/115d/post-title网站。com/audi/a1/16 tdi/post title这是我使用的代码;

## Auto Post Type
function autoCats() {
## Brand - Model - Version
register_taxonomy(
\'brand\',
\'auto\',
array(
    \'hierarchical\'      => true,
    \'label\'             => \'Marka / Model / Versiyon\',
    \'query_var\'         => true,
    \'rewrite\'           => array(
            \'slug\'          => \'marka\',
            \'with_front\'    => false
    )
)
);
}
add_action( \'init\', \'autoCats\', 0 );

function autoRegister() {
    $labels = array(
        \'name\' => _x( \'Araç\', \'catchthemes_custom_post\',\'catchthemes\' ),
        \'singular_name\' => _x( \'Araç\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'add_new\' => _x( \'Araç Ekle\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'add_new_item\' => _x( \'Yeni Bir Araç Ekle\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'edit_item\' => _x( \'Aracı Düzenleyin\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'new_item\' => _x( \'Yeni Araç\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'view_item\' => _x( \'Aracı Önizleyin\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'search_items\' => _x( \'Araç Ara\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'not_found\' => _x( \'Henüz Araç Eklenmemiş\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'not_found_in_trash\' => _x( \'Çöp Kutusunda Birşey Bulunamadı\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'parent_item_colon\' => _x( \'Parent ThemePost:\', \'catchthemes_custom_post\', \'catchthemes\' ),
        \'menu_name\' => _x( \'Araçlar\', \'catchthemes_custom_post\', \'catchthemes\' ),
);

$args = array(
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => \'Araç\',
        \'supports\' => array( \'title\', \'thumbnail\', \'editor\', \'comments\', \'custom-fields\' ),
        \'taxonomies\' => array(\'brand\', \'post_tag\', \'auto_cat\'), // this is IMPORTANT
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => get_stylesheet_directory_uri() . \'/img/iconAuto.png\',
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'query_var\' => true,
        \'can_export\' => true,
        \'hierarchical\' => true,
        //\'rewrite\' => true <-- this is what you need!
        //\'rewrite\' => array(\'slug\' => \'%auto_cat%/%brand%\',\'with_front\' => false),
        \'public\' => true,
        \'has_archive\' => \'auto\',
        \'capability_type\' => \'post\'
);
register_post_type( \'auto\', $args );
}
add_action( \'init\', \'autoRegister\', 20 );

1 个回复
SO网友:Domain

转到wordpress设置页面中的永久链接设置,并将永久链接结构更改为此。

 https://mysite.com/%category%/%postname%/
现在在中添加此代码。htaccess文件来实现permalink结构。

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

结束

相关推荐

Custom permalinks structure

我希望有这样的结构:www.mysite.com/2013 (必须显示2013年的所有职位)www.mysite.com/my-category/2013 (必须显示2013年和“我的类别”类别的所有帖子)www.mysite.com/my-category/my-tag/ (必须显示所有类别为“我的类别”和标记为“我的标记”的帖子)www.mysite.com/my-category/ (必须显示“我的类别”类别的所有帖子)www.mysite.com/my-