2014-10-31 75 views
2

我正在使用偉大和死亡的簡單instafeed.js將我的兩個Instagram視頻拖入我的個人網頁。它正在工作,但我還沒有找到一個選項來過濾視頻結果。目前它顯示圖像和視頻的組合。我想要的所有結果都是視頻。僅顯示instagram視頻的篩選結果 - instafeed.js

<script type="text/javascript"> 
    var feed = new Instafeed({ 
    limit: '10', 
    sortBy: 'most-liked', 
    resolution: 'standard_resolution', 
    clientId: '467ede5a6b9b48ae8e03f4e2582aeeb3', 
    template:'<div class="tile"><div class="text"><b>{{likes}} &hearts; </b>{{model.user.full_name}}</div><img class="item" src="{{image}}"></div>' 
    }); 
</script> 

<div id="instafeed"></div> 
+1

@StevenSchobert它似乎是你的開發者。你能幫忙嗎? – 2014-10-31 04:25:20

回答

3

可以使用filter選項:

var feed = new Instafeed({ 
    limit: '10', 
    sortBy: 'most-liked', 
    resolution: 'standard_resolution', 
    clientId: 'xxxxx', 
    template:'<div class="tile"><div class="text"><b>{{likes}} &hearts; </b>{{model.user.full_name}}</div><img class="item" src="{{image}}"></div>', 
    filter: function(image) { 
    return image.type === 'video'; 
    } 
}); 

這將通過函數運行每個image。該功能將檢查image.type是否爲video。如果不是,則該函數返回false,它告訴Instafeed.js從結果中排除該圖像。

注意:確保您至少使用Instafeed.js的v1.3版本,其中包含過濾器選項。

+0

完美,想象一下,我也可以只爲圖像做反之亦然。我可以過濾位置嗎? – 2014-10-31 22:01:31

+0

是的,你可以做'return image.type ==='image';'只獲取圖片!您也可以按位置進行過濾,但由於Instagram會將地點作爲地理座標返回,因此它需要更多的代碼。希望有所幫助! – 2014-10-31 22:32:38

+0

太棒了!我可以返回一個'image.type ==='video''的數值嗎? – 2014-11-01 03:24:00