如何访问 Tumblr 主题中的 Post Slug?
我想在我的 Tumblr 主题中写入一个规范标签,并且我需要(完整)网址的 slug。我如何访问模板中的 posts-slug?我只能访问 PostId。我当前的代码如下所示:
<link rel="canonical" href="http://domain.com/blog/{block:PostTitle}post/{PostID}{/block:PostTitle}" />
我想要的是这样的:
<link rel="canonical" href="http://domain.com/blog/{block:PostTitle}post/{PostID}/{PostSlug}{/block:PostTitle}" />
我尝试了以下标签(这显然不起作用......):
{slug}
{PostSlug}
{Postslug}
让我感到有趣的是,API 在每个帖子上都给出了一个 slug-key ,尝试:
http://(YOU).tumblr.com/api/read?debug=1
感谢您的任何提示和建议。
编辑:我已经扫描了 http://www.tumblr.com/docs/en/custom_themes 寻求提示 - 但没有发现任何有用的东西。
I want to write a canonical tag into my Tumblr theme, and i need the slug for the (full) url. How can i access the posts-slug within the template? I just have access to the PostId. My current code looks like this:
<link rel="canonical" href="http://domain.com/blog/{block:PostTitle}post/{PostID}{/block:PostTitle}" />
What i want to have is something like this:
<link rel="canonical" href="http://domain.com/blog/{block:PostTitle}post/{PostID}/{PostSlug}{/block:PostTitle}" />
I tried the following tags (which obviously did not work...):
{slug}
{PostSlug}
{Postslug}
What amuses me is, that the API gives out a slug-key on every post, try:
http://(YOU).tumblr.com/api/read?debug=1
Thanks for any hints and suggestions.
Edit: I already scanned http://www.tumblr.com/docs/en/custom_themes for hints - but found nothing useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
帖子 slug 不能作为 Tumblr 主题 DSL 中的令牌使用。我不确定这是否是故意遗漏,因为帖子标题在 Tumblr 上是可选的(您可以手动设置一个,但如果您不这样做,您的帖子将仅显示其数字 ID)。但是,您可以从 {Permalink} 令牌 插入的链接中解析它,即按照以下方式将其包含在模板中的某个隐藏元素中
(如果愿意,请隐藏跨度),然后使用 JavaScript 检索并解析它:
The post slug is not available as a token in Tumblr’s theme DSL. I’m not sure if this is an intentional omission, as post slugs are optional on Tumblr (you can manually set one, but if you don’t your post just goes by its numeric ID). However, you can parse it out of the link inserted by the {Permalink} token, i.e. include it in some hidden element in your template along the lines of
(hide the span if you will), then retrieve and parse it with JavaScript: