WordPress的自定义永久链接的只是职位 [英] Wordpress Custom Permalink for Just Posts

查看:92
本文介绍了WordPress的自定义永久链接的只是职位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Wordpress安装具有三种发布类型:页面,发布和投资组合.当前结构如下:

My Wordpress install has three post types: pages, posts, and portfolio. The current structure is as follows:

  • 页面:example.com/page-name
  • 帖子列表页面:example.com/blog
  • 个人帖子:example.com/post-name
  • 作品集列表页面:example.com/portfolio
  • 个人投资组合发布:example.com/portfolio/portfolio-name.
  • page: example.com/page-name,
  • post listing page: example.com/blog,
  • individual post: example.com/post-name,
  • portfolio listing page: example.com/portfolio,
  • individual portfolio post: example.com/portfolio/portfolio-name.

我要更改的内容是各个帖子的永久链接,但没有别的.我希望它成为example.com/blog/post-name.

The thing I'd like to change is the individual post permalink, but nothing else. I'd like it to become example.com/blog/post-name.

我找不到说明如何进行更改而不影响其他类型的文档.

I can't find documentation that shows how to make this change without affecting the other types.

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

EDIT : My current permalink structure is set up to be /%postname%/, and under Reading Settings, my posts page is set to Blog.

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',
)
));

推荐答案

您只需要将/blog/%postname%/设置为永久链接结构,就不会更改页面的永久链接.

You simply have to set /blog/%postname%/ as your permalinks structure, this will not change your pages permalinks.

为保持投资组合永久链接,您应在以下情况下将 with_front 设置为false您可以注册此帖子类型.

And to keep your portfolio permalinks, you should set with_front to false when you register this post type.

'with_front' => bool应该在永久结构之前加上 前基地. (例如:如果您的永久链接结构为/blog/,则您的 链接将为:false->/news/true->/blog/news/).默认为true

'with_front' => bool Should the permastruct be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true

之后,您应该刷新Wordpress重写规则.

with_front参数是rewrite参数:

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

这篇关于WordPress的自定义永久链接的只是职位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆