• Resolved skepticp

    (@skepticp)


    Hello,

    I upgraded to the pro version of this plugin today at https://www.skepticspath.org so that I could display multiple banners. However, what I would like to do is randomly display ONE of a set of banners, and not display multiple banners all at once. Is this possible?

    Thanks,

    Scott

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author rpetersen29

    (@rpetersen29)

    Hi @skepticp

    Simple Banner does allow you to display banners one after the other using the Start After Date and Remove After Date set. But if you want to randomly show banners when a user comes to your site you will need some custom Javascript. Essentially you would just create a random number generator and then show or hide banners base on that number. First you would set display: none; in all of your .simple-banner { custom CSS textfields. And the Website Custom Javascript would look something like:

    jQuery(document).ready(function ($) {
    const random = Math.ceil(Math.random() * (5))
    const banner_id = random === 1 ? '' :
    _${random};
    if (document.getElementById(simple-banner${banner_id})) document.getElementById(strings.simpleBanner).style.display = 'block';
    }

    Let me know how that works.

    Thread Starter skepticp

    (@skepticp)

    Hi,

    I’m not a javascript expert, but I took a shot and it isn’t yet working. Do you want to check it out? I have the banner set to display on some pages and not others. But this page should work as a test:

    https://www.skepticspath.org/blog/

    Here’s the code:

    jQuery(document).ready(function ($) {
    const random = Math.ceil(Math.random() * 2);
    const banner_id = random === 1 ? '' :
    _${random};
    const elementId = simple-banner${banner_id};
    const element = document.getElementById(elementId);
    if (element) {
    element.style.display = 'block';
    }
    });
    • This reply was modified 5 months, 2 weeks ago by skepticp.
    • This reply was modified 5 months, 2 weeks ago by skepticp.
    • This reply was modified 5 months, 2 weeks ago by skepticp.
    • This reply was modified 5 months, 2 weeks ago by skepticp.
    Thread Starter skepticp

    (@skepticp)

    I got it to work! I had pasted the code in CSS instead of Javascript. Thank you!

    Plugin Author rpetersen29

    (@rpetersen29)

    Great! Glad it worked.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.