• Resolved evilbeet

    (@evilbeet)


    I’ve been asked to change the ad code that runs only on three specific posts — on the other posts the regular ads will run. I tried to piece together some PHP code for it and came up with this:

    <?php if( ($post->ID == 43751) || ($post->ID == 43647) || ($post->ID == 43611)) { ?> 
    
    <iframe id="Adv1" src="https://ad.doubleclick.net/adi/real.filmcom/evilbeetgossip;pageurl=/evilbeetgossip;cat=tvondvd;subcat=;contentid=;dcopt=ist;sz=728x90;ord=14456755;tile=1"
    width="728" height="90" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
    </iframe>
    
    <?php } ?> 
    
    <?php else { ?>
    
    <iframe id="Adv1" src="https://ad.doubleclick.net/adi/real.filmcom/evilbeetgossip;pageurl=/evilbeetgossip;cat=celebrities;subcat=;contentid=;dcopt=ist;sz=728x90;ord=14456755;tile=1"
    width="728" height="90" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
    </iframe>
    
    <?php } ?>

    Unfortunately when I put this code in header.php the site doesn’t load. I’m sure there’s some parsing problem but I don’t have enough knowledge of PHP to figure out what it is. Help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Have a check with these steps:

    – Open index.php file of your wordpress theme.
    – Search the code:

    <?php endwhile; ?>

    Add this code before that:

    <?php if(!$show_ads){ ?>
    Your Advertisement Code here….
    <?php $show_ads = 1; } ?>

    Thanks,

    Shane G.

    See: https://codex.www.ads-software.com/Conditional_Tags#A_Single_Post_Page

    Try this format and make sure it’s in the <body> section:

    <?php if (is_single(array('1','2'))) { ?>
    <!-- code here -->
    
    <?php } else { ?>
    <!-- code here -->
    
    <?php } ?>

    I think (if I’m not terribly wrong), your script can’t parse and return any post related information unless you do a query posts. Since you try to include the conditional in the header.php, you have run a sql query for posts to make it work.

    S.K

    Thread Starter evilbeet

    (@evilbeet)

    Oh, thanks, I didn’t know about this is_single() function. I used the code you suggested and it’s working now. Thank you SO much, I really appreciate the prompt responses!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Code to Run Specific Ads on Specific Posts’ is closed to new replies.