Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How can i use pockets to display random images in a directory on my server?

CCartersCCarters New
edited March 2017 in Vanilla 2.0 - 2.8

as title suggests i am a bit lost.

I only know Java and C, so javascript and html are not under my belt.

I want my pocket to display one of the 5 images(at random) in a directory on my forum. How can I do this?

My images are in directory sitename.com/vanilla/images

here is the code I got so far:

var img = ["1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png"]
function imgRandom(imgArr) {
return imgArr[Math.floor(Math.random() * imgArr.length)];
}
console.log(imgRandom(img));

but its just showing the code in the pocket... no image coming up

Edit: I added script tags now it looks like the pocket recognizes it as jaavscript, but it still doesn't inflate the images.

Comments

  • Ok... so my images will only appear before the foot, no matter where I set them to be. What the heck gives?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited March 2017

    Pockets only will display correct html or JS it is only a div that gets created for the content you put in. If your content is wrong or badly coded, then the result is due to that not the pocket.

    I suggest you use the Galleries plugin to add images. Or use some kind of widget that will create a gallery of your images.

    Try the looking at the Widgets plugin for guidance as to how to create your own custom modules with content.

  • CCartersCCarters New
    edited March 2017

    @vrijvlinder said:
    Pockets only will display correct html or JS it is only a div that gets created for the content you put in. If your content is wrong or badly coded, then the result is due to that not the pocket.

    I suggest you use the Galleries plugin to add images. Or use some kind of widget that will create a gallery of your images.

    Try the looking at the Widgets plugin for guidance as to how to create your own custom modules with content.

    Is that needed though ? I will just be using it for ads. Some users will pay me and I will take their banner and place it in a directory in my server. I just want to be able to randomize an image every time a user goes to my forum - i don't want anything complex. Kinda like google adsense but i am just hosting the ads on my server.

    Say my /images folder has 10 images - all same size. I want to be able to just display them under the panel like in pockets but have images randomized.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    You did not specify it was for adverts, you just said random images ... if what you want is to use adverts then you need the plugin made for that called AptAds ...

    I don't care how many images or what you want to use in a module.. only you care about that. If you don't specify your needs it is hard for anyone to help you out.

    So try out the plugin made for your purpose ... AptAds

  • CCartersCCarters New
    edited March 2017

    @vrijvlinder said:
    You did not specify it was for adverts, you just said random images ... if what you want is to use adverts then you need the plugin made for that called AptAds ...

    I don't care how many images or what you want to use in a module.. only you care about that. If you don't specify your needs it is hard for anyone to help you out.

    So try out the plugin made for your purpose ... AptAds

    eh? Am I not describing my needs? I told you that I want to place banners of adverts under the panel of my board. THese adverts will all be hosted on my server - and with each refresh they will change because they are randomized. I am asking how I can do this with pockets - like in my original question, how can I write the javascript code for this to work out and what is wrong with my initial code?

    pockets fits my needs perfectly... i just need the code part ofi t down

    p.s aptads doesn't work when I enable it on 2.2. "The addon could not be enabled because it generated a fatal error:"
    and no error description

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Ok then do not follow my advice and fix it yourself.. Pockets was not made for dynamic content , AptAds is. It's up to you.

    You can only bring a horse to water, but you can't make it drink...

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    aptads doesn't work when I enable it on 2.2

    Sorry , you did not mention you are using an old version that has security problems and is no longer supported here.

    If you want to continue getting help here, I suggest you update ASAP.

  • R_JR_J Ex-Fanboy Munich Admin
    edited March 2017

    I guess what you are missing is how to write out that random array entry you have got as html to your page. Modify that as you need it.

    <div class="Box BoxAdverts">
    <h4>Adverts</h4>
    <script>
    var images = Array('+1.png','-1.png','angry.png');
    var image = images[Math.floor(Math.random()*images.length)];
    document.write('<img src="/resources/emoji/' + image + '" alt="Advert" />');
    </script>
    </div>
    

    In order to have a nice format in the panel you should use that enclosing div.Box

    Please update your version as soon as possible. There should be no reason to still work with Vanilla 2.2 and its strongly advisable to always use the current release.

  • CCartersCCarters New
    edited March 2017

    @R_J said:
    I guess what you are missing is how to write out that random array entry you have got as html to your page. Modify that as you need it.

    In order to have a nice format in the panel you should use that enclosing div.Box

    Please update your version as soon as possible. There should be no reason to still work with Vanilla 2.2 and its strongly advisable to always use the current release.

    Thanks alot!! works great :D. Am using 2.2 because I need API to work. I have tried the 0.5.0 and 0.4.0 api release from the guy who made it , but it just wouldn't work for 2.3. That is why I downgraded to 2.2.1 and the API works fine. (I am using it for my phone app that I developed)

    Also, for my future reference(since I have never worked with html/js before) in the future if I wanted to put adverts on the header or footer - would it be in the same format as you have shown me?

  • R_JR_J Ex-Fanboy Munich Admin

    The script yes, but the other markup no. The script writes out an image which can be used in any pocket. But the div.Box is meant for the panel. You should enclose the script with a div, give it a custom class and style that to look as you like

Sign In or Register to comment.