简体   繁体   English

博客帖子的自定义WordPress帖子类型

[英]Custom WordPress Post Type for Blog Posts

I am building a WordPress theme in which the blog posts are made using a custom post type titled 'blogs' 我正在构建一个WordPress主题,其中的博客帖子是使用名为“blogs”的自定义帖子类型制作的

The blog page is located at http://website.com/blog/ and when a post of type 'blogs' is posted, it is posted only to the /blog/ page. 该博客页面位于http://website.com/blog/ ,当发布“博客”类型的帖子时,它仅发布到/ blog /页面。 My problem is that when I click on a blog title to view the single blog the URL is redirected to http://website.com/post-title and not http://website.com/blog/post-title . 我的问题是,当我点击博客标题查看单个博客时,URL被重定向到http://website.com/post-title而不是http://website.com/blog/post-title But when I add 'rewrite' => array('slug' => 'blog') to the custom post type I get a 'Redirect Loop' error. 但是当我将'rewrite' => array('slug' => 'blog')到自定义帖子类型时,我收到了“重定向循环”错误。

How can I make the post title append the current url with /blog/? 如何使帖子标题附加/ blog /?

Have you tried to refresh your permalink rewrite rules after adding that slug by visiting Settings → Permalinks in wp-admin? 您是否尝试通过访问wp-admin中的设置→永久链接添加该slug后刷新永久链接重写规则? If that doesn't work, try hard flushing your rewrite rules ( http://codex.wordpress.org/Function_Reference/flush_rewrite_rules ). 如果这不起作用,请尝试刷新您的重写规则( http://codex.wordpress.org/Function_Reference/flush_rewrite_rules )。

I'm not exactly sure why you're even creating a custom post type "blogs". 我不确定你为什么甚至创建一个自定义的帖子类型“博客”。 Wordpress is essentially a blog by default. 默认情况下,Wordpress本质上是一个博客。 The permalink structure can be changed by going to Settings > Permalinks and updating the custom structure to /blog/%postname%/ 永久链接结构可以通过转到Settings > Permalinks并将自定义结构更新为/blog/%postname%/来更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM