Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用TumblrAPI调用文本帖子中的图像_Javascript_Jquery_Image_Tumblr - Fatal编程技术网

Javascript 使用TumblrAPI调用文本帖子中的图像

Javascript 使用TumblrAPI调用文本帖子中的图像,javascript,jquery,image,tumblr,Javascript,Jquery,Image,Tumblr,我正在使用Bandit Design()创建的特色帖子插件,我想将文本帖子中的图片包括在特色帖子列表中(如果你想知道的话,这实际上只是一篇帖子,下面有帖子标题的图片)。问题是tumblrapi没有在文本帖子中包含照片参数(您可以调用帖子的整个主体,但这在这里并不理想)。我的Javascript知识的深度可以描述为“足以让事情以某种方式工作,但更可能只是破坏事情”,因此解决方案在这里可能相当明显,我只是错过了它 我现在拥有的代码: /* TUMBLR FEATURED POSTS SCRIPT A

我正在使用Bandit Design()创建的特色帖子插件,我想将文本帖子中的图片包括在特色帖子列表中(如果你想知道的话,这实际上只是一篇帖子,下面有帖子标题的图片)。问题是tumblrapi没有在文本帖子中包含照片参数(您可以调用帖子的整个主体,但这在这里并不理想)。我的Javascript知识的深度可以描述为“足以让事情以某种方式工作,但更可能只是破坏事情”,因此解决方案在这里可能相当明显,我只是错过了它

我现在拥有的代码:

/*
TUMBLR FEATURED POSTS SCRIPT
Automatically gets all posts tagged with "featured" and lists them
REQUIRES JQUERY!
--------------------------------------
Created by james <at> bandit.co.nz
http://blog.bandit.co.nz

Some code borrowed from Jacob DeHart's AJAX Search:
http://blog.bandit.co.nz/post/80415548/tumblr-ajax-inline-search
    */
    Featured = {
'apiNum' : 50, // how many posts to read
'listId' : '_featured', // the id of the ul to write to
'tagName' : '_featured', // the name of the tag we're searching for
'linkAppend' : '', // html to append to the end of each linked post

'postDB' : [],
'listPos' : 0,
'doList' : function (where) {
    var li; var ul = $('#'+where);
    var titles = {"link":"link-text", "photo":"photo-caption", "quote":"quote-text", "regular":"regular-title", "video":"video-caption"}

    // cycle through post database
    pcount = Featured.postDB.length;
    for(i=Featured.listPos;i<pcount;i++) {
        p = Featured.postDB[i];
        if(p[titles[p.type]] != '') titlestr = p[titles[p.type]].replace(/<\/?[^>]+>/gi, '');
        else titlestr = p['url'];

        li = document.createElement('li');
        $(li).html('<a class="'+p.type+'" href="'+p["url-with-slug"]+'">'+p["regular-body"]+titlestr+Featured.linkAppend+'</a>');
        ul.append(li);

        Featured.listPos = pcount;
    }
},

'getData' : function() {
    $.get('/api/read/json?num='+Featured.apiNum+'&tagged='+Featured.tagName,
        function(data) {
            eval(data);
            for(i=0;i<tumblr_api_read.posts.length;i++) {
                Featured.postDB.push(tumblr_api_read.posts[i]);
                Featured.doList(Featured.listId);
            }
        }
    );
}
    };

    $(document).ready(function(){
Featured.getData();
    });
/*
TUMBLR特色帖子脚本
自动获取所有贴有“特色”标签的帖子并列出它们
需要JQUERY!
--------------------------------------
由詹姆斯创作的);
ul.附加(li);
Featured.listPos=pcount;
}
},
“getData”:函数(){
$.get('/api/read/json?num='+Featured.apiNum+'&taged='+Featured.tagName,
功能(数据){
评估(数据);

对于(i=0;i您可以将创建
li
的行更改为

$(li).append($(p['regular-body']).find('img')[0])
     .append('<a class="'+p.type+'" href="'+p["url-with-slug"]+'">'+titlestr+Featured.linkAppend+'</a>');
$(li).append($(p['regular-body']).find('img')[0])
.附加(“”);

这将找到文章正文的第一个图像,并将其添加到列表标题的正前方。

您可以更改创建
li
的行

$(li).append($(p['regular-body']).find('img')[0])
     .append('<a class="'+p.type+'" href="'+p["url-with-slug"]+'">'+titlestr+Featured.linkAppend+'</a>');
$(li).append($(p['regular-body']).find('img')[0])
.附加(“”);
这将找到文章正文中的第一个图像,并将其添加到列表中标题之前