在Tumblr中选择一个“特色”帖子?

4

我希望我的Tumblr首页能显示一个由“特色”标签选择的单个问答帖子,或者说是最近被打上“特色”标签的问答帖子。我没有看到任何内置的Tumblr标签可以实现这一点。

3个回答

3
我正在使用jQuery来获取默认情况下从分类“特色”中获取n篇精选文章。我已将此解决方案实现到我的主题中 - Purely
以下是三篇特色文章的屏幕截图: Screenshot of my blog 将此行添加到meta部分。
<meta name='text:Featured Tag' content='featured' />

在页面中添加jQuery库。
<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}

你可以根据想要显示的特色文章数量更改 if(vari <4){ 行。例如,要显示单个文章,则为 if(vari <2){。
我还添加了一些CSS类来设计输出。这可以在段落中声明。
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页面以查看是否已生成。


1

你所询问的并不是Tumblr的本地设置,换句话说,没有你可以简单勾选的偏好设置。

为了实现你上述描述的功能,你需要编辑当前主题代码或从头开始编写新主题。

为了仅显示一个标签为“特色”的顶部问题帖子,你需要使用jQuery/Javascript和Tumblr API。

这是相当复杂的编码,但如果你有兴趣,可以前往Tumblr API Codex


0
这可能有点晚了,但如果有帮助的话:我们的免费Single A主题内置了粘性帖子功能。这是第一个(也是唯一一个)拥有此功能的Tumblr主题。您可以在此处获取它:http://www.tumblr.com/theme/28638 或在此处了解更多信息:http://singleatheme.tumblr.com/。希望这能帮到您!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接