• Hello everyone. I was wondering if someone might be able to make some suggestions!

    I am working with this bit of code:

    <div class= “ads”>

    <?php if(function_exists(‘mba_display_banner’)) mba_display_banner(11);?>
    <?php if(function_exists(‘mba_display_banner’)) mba_display_banner(4);?>
    <?php if(function_exists(‘mba_display_banner’)) mba_display_banner(12);?>

    </div>

    This actually pulls my ads from max banner ads and puts them in my sidebar. Everything works correctly and places these ads statically.

    I am looking for something random.

    I want to make a list of say 20 ads (the above list only shows 3) and I want to take 3 of the ads from that list and place them randomly in the sidebar per page impression.

    Is this possible. Do I need to clarify this more? Can someone help me with this?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter momsheadquarters

    (@momsheadquarters)

    I should note that max banner ads plugin works with the sidebar widget to place ads in the sidebar without editing code. However, my theme does not work with the widget, hence, it does not work automatically. Therefore, I have to edit code to get them placed.

    Thank you in advance.

    Everything works correctly and places these ads statically.

    do the ads randomly/statisticaly change, or are they defined by the number in brackets?

    mba_display_banner(11)

    are these numbers consecutive, i.e. if you have 20 different ads, would they run from 1 to 20?

    if so, you could try:

    <div class= "ads">
    
    <?php $max_no = 20; //adjust to the actual max number of ads//
    
    $first_number = (int)rand(1,$max_no);
    do { $second_number = (int)rand(1,$max_no); } while ( $second_number == $first_number );
    do { $third_number = (int)rand(1,$max_no); } while ( $third_number == $first_number || $third_number == $second_number );
    
    <?php if(function_exists('mba_display_banner')) :
    mba_display_banner($first_number);
    mba_display_banner($second_number);
    mba_display_banner($third_number);
    endif; ?>
    
    </div>

    Thread Starter momsheadquarters

    (@momsheadquarters)

    The ads are defined by the number in the bracket. This is a unique number Max Banner Ads gives to each ad. However, the ad numbers are not consecutive because some numbers are assigned to larger ads that do not fit within the sidebar area ( ie leaderboards, lrge rectangles.)

    This will make it difficult won’t it?

    Thread Starter momsheadquarters

    (@momsheadquarters)

    I was hoping I would be able to manually ad the tags for the ads to the list and then randomly, or in the orderlisted, the ads would be placed into one of three spaces ( or 4 or whatever number of spaces I decide for the sidebar area) per page impression.

    I was hoping I would be able to manually ad the tags for the ads to the list and then randomly, or in the orderlisted, the ads would be placed into one of three spaces ( or 4 or whatever number of spaces I decide for the sidebar area) per page impression.

    feasible – the code got a bit longer:

    https://pastebin.com/9LqhUG6W

    first line: the array with the ad numbers;
    second line: the amount of ads to show;

    the code shows the ads randomly sorted; however, ‘in the order listed’ is possible.

    Thread Starter momsheadquarters

    (@momsheadquarters)

    Now i’m completely confused…but let me try a few things and let you know if I need clarification. Trial and error is sometimes the best teacher ??

    Thank you!!!

    Thread Starter momsheadquarters

    (@momsheadquarters)

    I can’t get his figured out. I just don’t know what to do with it. I pasted it in the appropriate place in my sidebar template and it didn’t work.

    This may be a silly question, but am I supposed to delete everything in the double forward slashes?

    The only thing I did was add the ad number (i.e. 11, 10, 4) to the right place and adjust for total amount of ads shown.

    I’m concerned because this: <?php if(function_exists(‘mba_display_banner’)) mba_display_banner(11);?> is the single line of code that pulls from max banner ads and this tag in broken in the code you wrote. Does this make a difference?

    What am I doing wrong here.

    <?php if(function_exists(‘mba_display_banner’)) mba_display_banner(11);?> is the single line of code that pulls from max banner ads and this tag in broken in the code you wrote.

    was the error message something like ‘unexpected { …’ ?

    my bad, and sorry for the confusion – the pasted code had an error;

    repaired:

    https://pastebin.com/Rr3gkDLH

    Thread Starter momsheadquarters

    (@momsheadquarters)

    Your a genius!!! I get so frustrated with this website because all I want to do is add content and found that with everything added things need to be tweaked.

    You’ve helped me out tremendously. When i’m so frustrated with an issue my husband asks me if I’ve asked the genus in the WP forums ??

    Thank you!!!!

    you are welcome ??

    it is a great website, and i can image that it is quite an effort to keep up with adding content and all the technicalities.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Creating a random list for sidebar’ is closed to new replies.