WordPress 中的自定义 URL 重写
我正在尝试使用 WordPress 实现自定义 URL 结构。 基本上,我的网站充当我的博客和我的作品集。 我想要一个“文章”部分和一个“作品集”部分。 我希望文章显示在文章页面上,作品集显示在作品集页面上。 应该很容易,除了我想要自定义 URL...
我想要像这样的 URL 设置:
文章页面: http://mydomain.com/discusses
具体文章: http://mydomain.com/discussed/%postname%
作品集页面: http://mydomain.com/does
具体设计: http://mydomain.com/Design/%postname%
我可以弄清楚该怎么做这种类型只有一次重写,但 WP 没有内置功能来执行这两项操作。 我只是想知道我应该从哪里开始或者我应该做什么...
问题也变成了,我想在这两个领域保留类别功能,所以也许需要通过自定义字段来实现? 并根据帖子的自定义字段添加新的重写规则? 我知道从哪里开始...
感谢您提供的任何帮助。
I am trying to achieve a custom URL structure with Wordpress. Basically, my site functions as my blog and my portfolio. I want to have an "Articles" section and a "Portfolio" section. I want the articles to display on the Articles page, and the portfolio on the Portfolio page. Should be easy, except on top of that I want custom URLs...
I want the URLs setup like this:
Articles page:
http://mydomain.com/discusses
Specific article:
http://mydomain.com/discussed/%postname%
Portfolio page:
http://mydomain.com/does
Specific design:
http://mydomain.com/designed/%postname%
I can figure out how to do only one rewrite of this type, but WP doesn't have built in functionality to do both. I'm just wondering where I should start or what I should do...
The problem also becomes, I want to retain category functionality in both areas, so maybe it needs to be achieved with Custom Fields? and add a new rewrite rule based on the custom field of a post? I have idea where to start...
Thanks for any help you can give.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这其实并不难做到。 我将逐页记录您需要做什么才能实现这一目标。
文章页面
在您的主题文件夹 (/wp-content/themes/your-theme/) 中创建一个名为discusses.php 的新模板,然后添加以下内容:
您不需要更多内容。 进入 WordPress 管理的页面部分,创建一个名为文章页面的新页面,并将 URL 设置为 /discusses/。 设置该页面的模板为讨论模板。 现在,进入管理中的“设置”→“阅读”部分,并将“帖子”页面设置为“文章”页面。 现在,您的所有博客文章都将显示在 URL /discusses/
特定文章
下,让所有文章显示为 /discuss/title 的最简单方法是将默认类别(在帖子 → 类别中)重命名为 Discuss 。 然后将您的永久链接设置为:
这将呈现每个帖子所需的链接。
投资组合页面和 特定设计页面
假设这将是某种自定义设计,最简单的方法是在页面部分创建自定义模板和页面,就像您为文章页面所做的那样,然后抛出自定义 HTML 和CSS 融入其中。 然后,我将每个特定的设计页面设置为页面部分中该页面的子页面。 您可以使用WPdb 类进行自定义查询以填充“Portfolio”页面。
This actually isn't that hard to do. I'll go down, page by page, what you would need to do to achieve this.
Articles Page
Create a new template in your theme folder (/wp-content/themes/your-theme/) called discusses.php and just add the following content:
You don't need any more content. Go into the Pages section of WordPress Admin and create a new page called Articles page and set the URL to be /discusses/. Set the template of this page to be Discusses Template. Now, go into the Settings → Reading section in Admin and set the Posts page to Articles page. Now all your blog posts will appear under the URL /discusses/
Specific Article
The easiest way to have all your articles appearing as /discussed/title is to rename the default category (in Posts → Categories) to discussed. Then set your permalinks to be:
This will render the links you need for each post.
Portfolio Page & Specific Design Page
Assuming this will be some kind of custom design, the easiest thing to do would be to create a custom template and Page in the pages section, as you did for the articles page, and throw your custom HTML and CSS into that. I would then set each specific design page to be a child page of that in the pages section. You can use the WPdb classs to make custom queries to populate the Portfolio page.