1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[TUT] Wordpress Rotating Ads - Inside Posts

Discussion in 'PHP & Perl' started by WPRipper, Jun 2, 2012.

  1. WPRipper

    WPRipper Supreme Member

    Joined:
    Mar 24, 2010
    Messages:
    1,379
    Likes Received:
    1,493
    Location:
    Proudly romanian
    Hy everyone. I always had problems with inserting ads inside WP post and i use a bunch of plugins but you dont have full control of what you are doin so i decided to digg a bit. So i found a simple solution to this is not much of a code but will help you im sure.

    So, first we need to add a function inside functions.php

    Code:
    // affiliate rotator
    function showads() {
      include("ads.php");
    return "$mybanners[$id]";
    }
    add_shortcode('aduri', 'showads');
    
    

    The code for ads.php

    Code:
    <?php
    $mybanners[1] = '<a href="YOUR AFF LINK 1" rel="nofollow"><img src="BANNER1"></a>';
    $mybanners[2] = '<a href="YOUR AFF LINK 2" rel="nofollow"><img src="BANNER2"></a>';
    $mybanners[3] = '<a href="YOUR AFF LINK 3" rel="nofollow"><img src="BANNER3"></a>';
    $mybanners[4] = '<a href="YOUR AFF LINK 4" rel="nofollow"><img src="BANNER4"></a>';
    $mybanners[5] = '<a href="YOUR AFF LINK 5" rel="nofollow"><img src="BANNER5"></a>';
     
    $id = rand(1,5);
    
    ?>
    
    
    Now all you need to do is place [aduri] shortcode where you want inside your post. Remember to change the path to your ads.php and your banners too. This is a short and easy solution for rotating ads without plugins.

    PS Please dont ask silly questions. If you cant make this work then ....IDK :)