表达式引擎:如何在文章链接中包含正确的类别 URL 标题?
我正在一个 EE 1.7.1 站点上工作,需要在主页上显示两个最新的文章条目。挑战在于我还需要将这些条目链接回各自的类别页面才能正确显示。
这是我到目前为止的代码:
{exp:weblog:entries weblog="articles" limit="2"}
<p><a href="{site_url}article/{url_title}">{title}</a></p>
{/exp:weblog:entries}
这是我想要做的,以便它引入相应的:
{exp:weblog:entries weblog="articles" limit="2"}
{categories}
<p><a href="{site_url}{category_url_title}/{url_title}">{title}</a></p>
{/categories}
{/exp:weblog:entries}
不幸的是,这不能正常工作。这样做的正确方法是什么?
谢谢。
I am working on an EE 1.7.1 site and need to display the two most recent article entries on the home page. The challenge is that I also need to link those entries back to their respective category pages to display properly.
Here is the code I have so far:
{exp:weblog:entries weblog="articles" limit="2"}
<p><a href="{site_url}article/{url_title}">{title}</a></p>
{/exp:weblog:entries}
Here is what I would like to do so that it brings in the corresponding :
{exp:weblog:entries weblog="articles" limit="2"}
{categories}
<p><a href="{site_url}{category_url_title}/{url_title}">{title}</a></p>
{/categories}
{/exp:weblog:entries}
Unfortunately this doesn't work correctly. What is the right way to do this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ExpressionEngine 本身没有在输出永久链接 URI 时将类别名称作为 URL 段包含在内的方法,这与 WordPress 不同。
当然可以做到,但需要围绕标准 EE URL 进行黑客攻击段。
如果您有一点点好奇,EE 上对此进行了更详细的讨论播客,Playgrounder 的 Episide #10 幕后花絮。
Dan Benjamin 和 Ryan Ireland 之间的相关讨论发生在 18:45 - 26:20 之间,Dan 详细介绍了他如何为 开发独特的永久链接结构游乐场:
ExpressionEngine doesn't natively have a method of including the Category Name as a URL Segment when outputting the Permalink URI, unlike, say, WordPress.
It can be done of course, but will require hacking around the standard EE URL Segments.
If you're even the least bit curious, this was discussed in more detail on the EE Podcast, Episide #10 Behind the Scenes at Playgrounder.
The relevant discussion between Dan Benjamin and Ryan Ireland occurs between 18:45 - 26:20, when Dan details how he developed the unique permalink structure for Playgrounder:
您可能需要在exp:weblog:entries 标记中添加dynamic="off" 参数。
You probably need to add dynamic="off" parameter in exp:weblog:entries tag.
您是否想显示最新的两个条目及其相关类别?例如:
如果这就是您想要做的,以下代码将输出上述内容:
Are you trying to show the latest two entries and their associated categories? Such as:
If that's what you're trying to do, the following code will output the above: