在 WordPress 3.0 中的自定义 post_type 永久链接中使用日期
我正在向 WordPress 添加自定义 post_type,并且希望永久链接结构如下所示:
/%post_type%/%year%/%monthnum%/%postname%/
我不知道如何添加日期标签。使用此代码,给我 /my_type/example-post-slug/
:
register_post_type( 'customtype', array(
...other options...
'rewrite' => array('slug' => 'my_type'),
));
如何包含日期?
I'm adding a custom post_type to Wordpress, and would like the permalink structure to look like this:
/%post_type%/%year%/%monthnum%/%postname%/
I can't figure out how to add the date tags. Using this code, gives me /my_type/example-post-slug/
:
register_post_type( 'customtype', array(
...other options...
'rewrite' => array('slug' => 'my_type'),
));
How do I include the dates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用插件自定义帖子类型永久链接来实现此目的。只需安装插件并在设置中更改永久链接格式即可。
You can achieve this with the plugin Custom Post Type Permalinks. Just install the plugin and change the permalink format in the settings.
我找到了一个部分解决方案,它允许在地址栏中加载页面时识别和保留永久链接,但不会在编辑屏幕或网站上帖子的其他链接中更新。
将以下内容添加到functions.php或特定于站点的插件中,将example-post-type替换为您的帖子类型的标识符。
这使用此处记录的重写 API
要查找有关理解该流程的更多提示,请参阅 在这里。
需要记住的一件事是,无论您如何执行此操作,两个帖子都不可能具有相同的标题,即使它们具有不同的日期。这是因为如果永久链接方案发生更改,它们可能会发生冲突并导致错误。
I have found a partial solution which allows for the permalink to be recognized and preserved upon loading the page in the address bar, but not updated in the edit screen or other links to the post on the site.
Add the following to functions.php or a site specific plugin, replacing example-post-type with the identifier of your post type.
This uses the Rewrite API documented here
To find more tips on understanding the process see here.
One thing to bear in mind is no matter how you do this, it is impossible for two posts to have the same slug, even if they have different dates. This is because if the permalink scheme is ever changed, they could clash and cause errors.
使用这个它可以100%工作:
Use this it's working 100% :