我希望我的Tumblr首页能显示一个由“特色”标签选择的单个问答帖子,或者说是最近被打上“特色”标签的问答帖子。我没有看到任何内置的Tumblr标签可以实现这一点。
我希望我的Tumblr首页能显示一个由“特色”标签选择的单个问答帖子,或者说是最近被打上“特色”标签的问答帖子。我没有看到任何内置的Tumblr标签可以实现这一点。
<meta name='text:Featured Tag' content='featured' />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
{block:IndexPage}
{block:IfFeaturedTag}
<h1 class="featured-subhead">
Featured Posts <a href="/tagged/{text:Featured Tag}"> + </a>
</h1>
{/block:IfFeaturedTag}
{/block:IndexPage}
将这些行添加到闭合标签之前
{block:IndexPage}{block:IfFeaturedTag}
<script>
var rssurl = '/tagged/{text:Featured Tag}/rss';
$.get(rssurl, function(data) {
$('.featured-subhead').append('<div class="featured-posts">');
var $xml = $(data);
var vari = 0;
$xml.find("item").each(function() {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
description: $this.find("description").text(),
pubDate: $this.find("pubDate").text(),
author: $this.find("author").text()
}
vari = vari +1;
if(vari <4){
$('.featured-subhead').append('<div class="featured-post" style="overflow:hidden;"><h2 class="featured-title"><a href="' + item.link + '">' + item.title + '</a></h2><div class="featured-post-description' + vari + '">' + item.description + '</div><div class="featured-post-link"><a href="' + item.link + '">Read More</a></div></div>');
//Do something with item here...
}
});
$('.featured-subhead').append('</div>');
});
{/block:IndexPage}{/block:IfFeaturedTag}
h1.featured-subhead
{
/* Heading of featured post */
}
.featured-posts
{
/* Outer box of all featured posts */
}
.featured-post
{
/* Inner box of each featured post */
}
h2.featured-title
{
/* Heading of each featured post */
}
.featured-post-description
{
/* Description or body of each featured post */
}
.featured-post-link
{
/* Link to Permalink page of each featured post */
}
这里只需要featured-subhead类。必须将其添加到精选文章的标题中。jQuery会在此之后添加精选文章。
它是如何工作的? 毫不意外。Tumblr为每个页面生成一个标签RSS页面。通过使用javascript,我正在获取该特定标签页并从XML元素中显示“n”个元素。有时,Tumblr需要更多时间(我不知道为什么)来生成新添加标签的RSS页面。请耐心等待,并尝试浏览your-blog.tumblr.com/tagged/featured/rss页面以查看是否已生成。
你所询问的并不是Tumblr的本地设置,换句话说,没有你可以简单勾选的偏好设置。
为了实现你上述描述的功能,你需要编辑当前主题代码或从头开始编写新主题。
为了仅显示一个标签为“特色”的顶部问题帖子,你需要使用jQuery/Javascript和Tumblr API。
这是相当复杂的编码,但如果你有兴趣,可以前往Tumblr API Codex。