使用 Tumblr Like Button 和无限滚动 [英] Using Tumblr Like Button with Infinite Scroll

查看:19
本文介绍了使用 Tumblr Like Button 和无限滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Infinite Scroll 中使用新的 Tumblr like 按钮(允许您的主题在主页上的单个 Tumblr 帖子上有一个 like 按钮)它们适用于第一个页面"的前 15 个帖子,但随后它加载另一个页面,喜欢按钮停止工作.这些是 Tumblr 在文档页面上给出的说明:

I'm trying to use the new Tumblr like buttons within Infinite Scroll (allowing your theme a like button on individual Tumblr posts from the homepage) they work for the first 15 posts of the first 'page' but then as soon as it loads another page the like button stops working. These are the instructions given from Tumblr on the Docs page:

功能:Tumblr.LikeButton.get_status_by_page(n)
说明:请求新的帖子页面后调用此函数.获取页面刚刚作为整数加载的数字.

Function: Tumblr.LikeButton.get_status_by_page(n)
Description: Call this function after requesting a new page of Posts. Takes the page number that was just loaded as an integer.

函数:Tumblr.LikeButton.get_status_by_post_ids([n,n,n])
描述:请求单个帖子的赞状态.采用一组帖子 ID.

Function: Tumblr.LikeButton.get_status_by_post_ids([n,n,n])
Description: Request Like status for individual posts. Takes an array of post IDs.

由于我不确定如何正确应用 JQuery 我不确定在哪里添加这些函数,这是我当前主题的 JS:

As I'm not sure how to properly apply JQuery I'm not sure where to add these functions, here is my JS for my current theme:

    // MASONRY
    var $container = $('#content');

    $container.imagesLoaded( function(){
        $container.masonry({
            itemSelector: '.entry',
            columnWidth: 220
        });
    });

    // INFINITE SCROLL
    $container.infinitescroll({
        navSelector  : '#pagination',
        nextSelector : '#pagination li a.pagination_nextlink',
        itemSelector : '.entry',
        loading: {
            img: 'http://static.tumblr.com/glziqhp/K37m9yaub/257__1_.gif'
        }
    },

    function( newElements ) {
        var $newElems = $( newElements ).css({
            opacity: 0
        });
        $newElems.imagesLoaded(function(){
            $newElems.animate({
                opacity: 1
            });
            $container.masonry(
                'appended', $newElems, true
            ); 
        });
    });

推荐答案

首先,您需要为每个帖子添加一个唯一的帖子 ID:

First you need to add a unique post ID to each of your posts:

<div class="entry masonry-brick" id="{PostID}">...</div>

文档提到在附加/加载新帖子(或新页面)后请求点赞状态:

The documentation mentions requesting the like status once the new posts (or new page) has been appended / loaded:

function( newElements ) {
    var $newElems = $( newElements ).css({
        opacity: 0
    });

    // Create Array of $newElems IDs
    var $newElemsIDs = $newElems.map(function () { 
        return this.id; 
    }).get();

    $newElems.imagesLoaded(function(){
        $newElems.animate({
            opacity: 1
        });
        $container.masonry(
            'appended', $newElems, true
        );

        // Let's just see what we have, remove console.log() if working
        console.log($newElems, $newElemsIDs);


        Tumblr.LikeButton.get_status_by_post_ids($newElemsIDs);
    });
});

我希望这为您指明了正确的方向.

I hope that points you in the right direction.

这篇关于使用 Tumblr Like Button 和无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆