【问题标题】:Select a single 'featured' post in Tumblr?在 Tumblr 中选择一个“精选”帖子?
【发布时间】:2010-12-02 15:19:11
【问题描述】:

我希望我的 Tumblr 主页显示一个由“精选”标签选择的问题/答案帖子,或者更确切地说是标记为“精选”的最新问题/答案帖子。我没有看到任何内置的 Tumblr 标签可以做到这一点。

【问题讨论】:

    标签: tumblr


    【解决方案1】:

    默认情况下,我正在使用 jQuery 从“精选”类别中获取精选帖子(其中 n 个)。我已经为我的主题实现了这个解决方案 - Purely

    这是一个屏幕截图(显示三个精选帖子) 添加这一行的元部分

    <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

    我还添加了一些 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 */
    }
    

    这里只需要特色副标题类。这必须添加到特色帖子的标题中。 jQuery 会在此之后添加精选帖子。

    它是如何工作的? 这里没有惊喜。 Tumblr 为每个页面生成一个标签 RSS 页面。通过使用 javascript,我正在获取该特定标签页面并显示来自 XML 元素的“n”个元素。有时,Tumblr 需要多一点时间(我不知道为什么)来生成新添加标签的 RSS 页面。请耐心等待并尝试浏览 your-blog.tumblr.com/tagged/featured/rss 页面以检查它是否已生成。

    【讨论】:

      【解决方案2】:

      您要问的不是 tumblr 的原生设置,换句话说,您没有可以简单检查的偏好设置。

      为了执行上述操作,您需要编辑当前主题代码,或者从头开始编写新主题。

      为了仅在顶部显示 1 个带有特色标签的问题帖子,您需要使用 jQuery/Javascript 和 Tumblr API。

      这是相当复杂的编码,但如果您愿意,请前往Tumblr API Codex

      【讨论】:

        【解决方案3】:

        这有点晚了,但如果它有任何帮助:我们免费的 Single A 主题具有内置的粘性帖子功能。它是第一个(也是唯一一个)拥有它的 tumblr 主题。你可以在这里得到它:http://www.tumblr.com/theme/28638 或在这里了解更多信息:http://singleatheme.tumblr.com/。希望这会有所帮助!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-14
          • 1970-01-01
          • 1970-01-01
          • 2021-10-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多