WordPress自定义固定链接即时帖

时间:2013-03-25 14:46:35

标签: wordpress custom-post-type permalinks

我的Wordpress安装有三种帖子类型:页面,帖子和组合。目前的结构如下:

  • 页面:example.com/page-name
  • 发布信息页面:example.com/blog
  • 个别帖子example.com/post-name
  • 投资组合列表页面:example.com/portfolio
  • 个人投资组合帖子:example.com/portfolio/portfolio-name

我想改变的是个人帖子固定链接,但没有别的。我希望它成为example.com/blog/post-name。

我找不到显示如何在不影响其他类型的情况下进行此更改的文档。

编辑: 我当前的永久链接结构设置为/%postname%/,在阅读设置下,我的帖子页面设置为博客。

register_post_type('portfolio', array(  
'label' => 'Portfolio Items',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => true,
'rewrite' => array('slug' => 'portfolio'),
'with_front' => false,
'query_var' => false,
'has_archive' => true,
'exclude_from_search' => false,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes'),
'taxonomies' => array('category','post_tag'),
'labels' => array (
    'name' => 'Portfolio Items',
    'singular_name' => 'Portfolio Item',
    'menu_name' => 'Portfolio Items',
    'add_new' => 'Add Portfolio Item',
    'add_new_item' => 'Add New Portfolio Item',
    'edit' => 'Edit',
    'edit_item' => 'Edit Portfolio Item',
    'new_item' => 'New Portfolio Item',
    'view' => 'View Portfolio Item',
    'view_item' => 'View Portfolio Item',
    'search_items' => 'Search Portfolio Items',
    'not_found' => 'No Portfolio Items Found',
    'not_found_in_trash' => 'No Portfolio Items Found in Trash',
    'parent' => 'Parent Portfolio Item',
)
));

1 个答案:

答案 0 :(得分:39)

您只需将/blog/%postname%/设置为永久链接结构,这不会更改您的网页永久链接。

为了保持您的投资组合固定链接,您应该在注册此帖子类型时将with_front设置为false

  

'with_front' => bool permastruct是否应该加上   前基地。 (例如:如果你的永久链接结构是/blog/,那么你的   链接将是:false->/news/true->/blog/news/)。默认为true

编辑1:之后您应该flush Wordpress rewrite rules

编辑2:with_front param是rewrite参数:

'rewrite' => array('slug' => 'portfolio', 'with_front' => false),