WordPress.org

Ready to get started?Download WordPress

Forums

Ad Inserter
[resolved] What if I have more than 16 ads? (6 posts)

  1. wowordpress
    Member
    Posted 4 months ago #

    Hello all,
    This plugin has only 16 code blocks, what if I have over 16 ads? like 20, 30, or more? How can I add more code blocks?

    Thank you in advance.

    https://wordpress.org/plugins/ad-inserter/

  2. spacetime
    Member
    Plugin Author

    Posted 4 months ago #

    Well, this plugin had only 8 code blocks few version ago.

    I can not imagine any real situation where you would need more than 16 ad positions.

  3. wowordpress
    Member
    Posted 4 months ago #

    Thank you for your reply.
    In fact, I do not need that many ad positions but only 3. However, I need to display different ads for different categories at the same spots, my website has more than 20 categories, I want to display different ads.
    For example, my site have an ad position that is below the post title, if a post is under Basketball category, I want to display a specific ad for Basketball category, if a post is under Football category, I want to display a specific ad for Football Category, etc.

  4. spacetime
    Member
    Plugin Author

    Posted 4 months ago #

    I see, but this is a very specific requirement.

    However, this can easily be achieved with current version using some simple PHP code for each block - enable PHP processing and write code to check for post categories.

  5. spacetime
    Member
    Plugin Author

    Posted 2 months ago #

    Closing the thread.

  6. KennyWithers
    Member
    Posted 1 week ago #

    Wowordpress, I needed the exact same thing; a way to display rotating iframes at the bottom of a post and have them change on page refresh. But, I also wanted different ads to show depending on the post category. I had a friend help me with the php code. I will add it below:

    <?php
    
    /*Enter the WordPress category number, then the url's that you want to rotate in the iframe*/
     $urls = array (
        207 => array("http://example.com/page1.html","http://example.com/page2.html"),
        208 => array("http://example.com/page1.html","http://example.com/page2.html")
            );
    
      /*This gets the category*/
      $category = get_the_category();
    
      /*This counts the number of urls in the selected category*/
      $randcategory = rand(0,(count($category)-1));
    
      /*this randomizes the urls in the category*/
      $category = $category[$randcategory];
    
      /*If more than one category is selected for a post, this randomizes all urls in the categories selected*/
      $rand = rand(0,(count($urls[$category->cat_ID])-1));
    
      /*This checks to see if there are urls in a category. If so, then it displays the random urls in an iframe. If not, then nothing appears including the iframe.*/
      if(!empty($urls[$category->cat_ID][ $rand ])){
      echo "<iframe width='' src='".$urls[$category->cat_ID][ $rand ]."'></iframe>";
      }
    ?>

    There are many ways of finding out what the category number is of a post in WordPress. You can hover over the category name in the WP Dashboard, and the number will be at the end of the url. You can also download the plugin "Reveal ID's". Also you can enter the following php code, and enter it in the WordPress Loop of your single.php page.

    <?php
      foreach((get_the_category()) as $category) {
      echo $category->cat_ID . ' ';
      }
    ?>

    You can then use this plugin to place the ads where ever you want on your site. Make sure you check the "Process PHP" checkbox. If you want to insert the ads somewhere other than the default locations in the plugin, you can enable "PHP function adinserter for block 1" then add the code <?php echo adinserter (1); ?> anywhere in your pages using the editor.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.