• Resolved sgwatwp

    (@sgwatwp)


    I think your plugin is great and it’s been working pretty well on my site (though the impressions counter seems to be having issues… but that’s not what this question is about).

    I have multiple areas for ads on my site. For example, I have 3 sidebar button ad slots. The appear as 300×250 images stacked on top of each other in the sidebar. I can put multiple ads into these 3 ad locations without issue by associating each location with a group. When they page loads, each location is filled with an ad associated with that group at random. This all works as expected.

    What I would like to do is guarantee that the same ad doesn’t appear in more than 1 of the 3 locations even if it is part of all 3 groups.

    If my sidebar has 3 images like this…

    |——|
    | G1 |
    |——|
    |——|
    | G2 |
    |——|
    |——|
    | G3 |
    |——|

    G1 = A, B, C
    G2 = A, B, D
    G3 = B, C, E

    Where G1 is “group 1” is and A is ad “A”, I don’t want A, B, C, D or E to show up multiple times in these three locations. If A is randomly placed in the G1 location I don’t want it to be an available ad for G2 or G3.

    I realize this probably isn’t a feature you are looking to add to the plugin, so I was wondering if you could point me in the right direction so that I can do it myself. I’m competent in php and sql, so where should I look in the plugin files to start something like this. Do you have any general recommendations?

    Thanks

    https://www.ads-software.com/plugins/ads-by-datafeedrcom/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author datafeedr

    (@datafeedrcom)

    Hi

    There’s only 1 query that the plugin runs to serve ads. That’s in the query() method in this file: ~/ads-by-datafeedrcom/inc/dfads.class.php

    You’ll need to edit that query.

    Eric

    Thread Starter sgwatwp

    (@sgwatwp)

    Eric,

    Thanks for the tip. I think I solved my problem. Maybe this is something you want to include in the trunk of this project as an option to turn on and off as users wish?

    Basically I decided to use a static private array member of the DFADS class.

    Each time an ad result is returned by the query, I grab its ID and put that in the array. When I perform the query I check and make sure the IDs of the results I’m pulling back are not in the array’s values.

    This works great for guaranteeing that no ad is displayed more than once on a page.

    Class DFADS() {
        private static $excluded_ads = array();
    
        function get_ads( $args ) {
            ...
            // Get ads.
            $ads = $this->query();
    
            ...
            foreach ($ads as $ad) {
                self::$excluded_ads[] = $ad->ID;
            }
        }
        ...
        function query() {
            ...
            $exclude_ads = $this->sql_get_excluded_ads();
    
            // SQL WHERE clause construction
            ...
            AND (
                    p.ID NOT IN ($exclude_ads)
                )
            ...
        }
        ...
        function sql_get_excluded_ads() {
            if (empty(self::$excluded_ads)){
                return '-1';
            } else {
                return implode(',',self::$excluded_ads);
            }
        }
    }

    And that’s it basically. I’m also looking into adding functionality that would restrict a single advertiser’s ads from taking a majority of the ad spots if there are multiple advertisers and they should be sharing the available space.

    Thread Starter sgwatwp

    (@sgwatwp)

    This specific question is resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I want to conditionally display ads based on other ads’ is closed to new replies.