Photos in different Ivs using instafeed.js

Asked

Viewed 1,087 times

3

I’m using the instafeed.js API. I wanted instead of all photos appearing in the same div to appear one per div. I tried to use this example but it didn’t work: example instafeed.js on multiple Ivs, create multiple instafeed instances, one for each div. Any ideas?

instafeed:

var feed = new Instafeed({
    target: 'instafeed1',
    get: 'tagged',
    tagName: 'pizza',
    clientId: '*******',
    limit: 1
});

var feed = new Instafeed({
    target: 'instafeed2',
    get: 'tagged',
    tagName: 'pizza',
    clientId: '******',
    limit: 1
});

 var feed = new Instafeed({
    target: 'instafeed3',
    get: 'tagged',
    tagName: 'pizza',
    clientId: '******',
    limit: 1
});

 var feed = new Instafeed({
    target: 'instafeed4',
    get: 'tagged',
    tagName: 'pizza',
    clientId: '******',
    limit: 1
});

 var feed = new Instafeed({
    target: 'instafeed5',
    get: 'tagged',
    tagName: 'pizza',
    clientId: '******',
    limit: 1
});

 var feed = new Instafeed({
    target: 'instafeed6',
    get: 'tagged',
    tagName: 'pizza',
    clientId: '******',
    limit: 1
});
instafeed1Feed.run();
instafeed2Feed.run();
instafeed3Feed.run();
instafeed4Feed.run();
instafeed5Feed.run();
instafeed6Feed.run();

HTML:

<div id="where1">
    <div></div>
    <div id="instafeed1"></div>
    <div id="instafeed2"></div>
    <div id="instafeed3"></div>
    <div id="instafeed4"></div>
</div>

<div id="where5">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div id="instafeed5"></div>
    <div id="instafeed6"></div>
</div>
  • In the plugin website has a "Templating" section. Have you tried using that?

  • It doesn’t work, I don’t think it’s good for this

  • Sorry @Ucas, you were right. Obgado

1 answer

2


That’s exactly what the Lucas spoke, use the option template of instafeed and also the function getMultipleTags() posted in the Issue linked #12.

<style>
.insta-pic {
    background-color: #fcc;
    padding: 5px;
    margin: 5px;
    width: 150px;
    height: 150px;
    float: left;
}
</style>
<h3>Rock Tag</h3>
    <div id="rockTag"></div>
<h3>Glass Tag</h3>
    <div id="glassTag"></div>
<h3>Wood Tag</h3>
    <div id="woodTag"></div>
<script>
function getMultipleTags (tags,client) {
    var feeds = [];
    for (var i=0, len=tags.length; i < len; i++) {
        feeds.push(new Instafeed({
            get: 'tagged',
            tagName: tags[i],
            target: tags[i] + "Tag",
            clientId: client,
            template: '<div class="insta-pic"><a href="{{link}}"><img src="{{image}}" /></a></div>'
        }));
    }
    return feeds;
}
var  client = 'NUMERO-ID';
if( client ) {
    // get multiple tags
    var myTags = getMultipleTags(['glass', 'wood', 'rock'],client);
    // run each instance
    for(var i=0, len=myTags.length; i < len; i++) {
        myTags[i].run();
    }
}
</script>

Demo on Jsfiddle.


  • And can I give this class ('insta-pic') to several Ivs? The tag will always be the same, but the Divs is will be spread across the page with no particular pattern, one photo per div.

  • Yes, you can. Just play there in Jsfiddle until you get the desired result.

  • Very obnoxious, it worked

  • Just one last thing: I wanted it to always be the same tag (pizza) on the 6 Ivs and I can’t because the myTags array cannot have equal Indexes

  • That’s it another question, Miguel ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.