结果我需要遍历帖子并调用tumblr api来获取音频帖子的嵌入代码.
我把代码放在下面希望它会帮助某人:
我在tumblr主题中有以下的html代码:
{块:帖子}
<div id="{PostID}" class="posts {block:Photo}photo-post{/block:Photo} {block:Video}video-post{/block:Video} {block:Audio}audio-post{/block:Audio} {block:Photoset}photoset-post{/block:Photoset}">
Run Code Online (Sandbox Code Playgroud)然后在砌量的回调(见下文)中,我有以下代码:
/* repair audio players*/
$('.audioplayerinto').each(function(){
var audioID = $(this).attr("id");
var $audioPost = $(this);
$.ajax({
url: 'http://myblog.tumblr.com/api/read/json?id=' + audioID,
dataType: 'jsonp',
timeout: 50000,
success: function(data){
$audioPost.html(data.posts[0]["audio-player"]);
/*
$audioPost.append('\x3cdiv style=\x22background-color:white;height:30px\x22 class=\x22audio_player\x22\x3e' + data.posts[0]['audio-player'] +'\x3c/div\x3e');
alert("It worked");
*/
}
}
Run Code Online (Sandbox Code Playgroud)回调代码如下所示:
if($content.infinitescroll) {
$content.masonry({
itemSelector: '.posts',
//columnWidth: 235,
isAnimated: true
}),
$content.infinitescroll({
navSelector : 'div#pagination',
nextSelector : 'div#pagination div#nextPage a',
itemSelector : '.posts',
loading: {
finishedMsg: '',
img: 'http://static.tumblr.com/dbek3sy/pX1lrx8xv/ajax-loader.gif'
},
bufferPx : 500,
debug : false,
},
// call masonry as a callback.
function( newElements ) {
Run Code Online (Sandbox Code Playgroud)