使 Wordpress 使用页面而不是类别 [英] Make Wordpress use the page instead of category
问题描述
我进行了大量研究,并找到了一些解决方案,如下所示:https://wordpress.stackexchange.com/questions/106042/force-wordpress-to-show-pages-instead-of-category
I did a great amount of research and came across some solutions like this: https://wordpress.stackexchange.com/questions/106042/force-wordpress-to-show-pages-instead-of-category
但它仍然不是正是我正在寻找的.首先让我解释一下问题.
But still it isn't exactly what I'm looking for. First of all let me explain the problem.
我创建了一个页面/blog/和一个类别博客",它们都使用了永久链接/blog/,禁用了/category/永久链接,因此 SEO 将是正确的.
I made a page /blog/ and a category 'blog' both make use of the permalink /blog/, disabled the /category/ permalink so the SEO will be correct.
我遇到的解决方案不符合以下要求:
The solutions I came across didn't match the following requirements:
- 不使用 301 重定向
- 在 Wordpress 中禁用/category/使用.
- 还可以仅在页面 ID 使用相同的 slug 时替换类别.
我只是想让 Wordpress 显示页面而不是类别.
I simply like to tell Wordpress to display the page instead of the category.
为什么不直接编辑类别模板?
因为我创建的页面使用了 Visual Composer(Post Masonry Grid),所以我不能简单地移动设计.
Because the page I created uses Visual Composer (Post Masonry Grid) so I can't simple move the design.
为什么不直接使用重定向?
我想,但博客的永久链接与页面相同(SEO 目的.)
I would like to but the permalink of the blog is the same as the page (SEO purpose.)
推荐答案
我知道几年后还没有解决方案,但是我遇到了您在一个站点上描述的完全相同的问题,而该站点在其他站点中也可以使用.因此,我对不同之处进行了一些研究,并在其他人遇到相同问题时提供帮助.
I know it's a few years later with no solution, but I had the exact same problem you described on one site that was working in other sites. So I did some research on what was different and to help others should they run into the same issue.
背景
example.com 是域
example.com is the domain
我有一个名为foobar"的 WP 页面,其中包含内容
I have a WP page called "foobar" with content
我有一个名为foobar"的 WP 帖子类别
I have a WP post category called "foobar"
我有一个 WP 帖子,标题为与 foobars 相关的有趣事情",类别设置为foobar"
I have a WP post entitled "fun things to do with foobars", and the category is set to "foobar"
期望
当我转到
example.com/foobar
时,我想查看有关 foobars 的页面,而不是显示该类别的所有博客文章的 WP 类别页面.
When I go to
example.com/foobar
, I want to see the page about foobars, not a WP category page that shows all blog posts with that category.
当我转到有关有趣事物的博客文章时,URL 为 example.com/foobar/fun-things-to-do-with-foobars/
When I go to the blog post about fun things, the URL is example.com/foobar/fun-things-to-do-with-foobars/
设置
这是我的设置(它不需要任何额外的插件或代码编辑)几个已安装的插件是 WP Rocket 和 Yoast,我将在本主题中重点介绍.
Here's my setup (it does not require any additional plugins or code edits) A couple of installed plugins are WP Rocket and Yoast on which I'll focus in this thread.
WP 仪表板->设置->固定链接
WP Dashboard->Settings->Permalinks
选择自定义结构"并在字段中输入/%category%/%postname%/
Select "Custom Structure" and enter /%category%/%postname%/
in the field
在同一页面上,将Category base"更改为一个点.."(没有引号,只有一个点/句点/句号
On the same page, change "Category base" to a single dot. "." (no quotes, just a single dot/period/full stop
我安装了 Yoast,我已将其设置为覆盖永久链接设置,但我相信这会破坏我手头的任务.
I have Yoast installed, which I had set up to override the permalink settings, but I believe this messed up my task at hand.
WP Dashboard->SEO->Advanced->Permalinks(tab)
WP Dashboard->SEO->Advanced->Permalinks(tab)
更改网址->去除类别基础..." = Keep
"Change URLs->Strip the category base..." = Keep
然后你需要清除缓存.我使用 WP Rocket 进行缓存,所以我刷新了缓存,现在一切正常.
Then you need to clear the cache. I use WP Rocket for caching, so I flushed the cache and everything now works the way it should.
编辑:确保在第 3 步和第 5 步之后保存更改
Edit: make sure you save your changes after steps 3 and 5
这篇关于使 Wordpress 使用页面而不是类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!