1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Fun with Wordpress Functions

Discussion in 'PHP' started by AdamBaird, Sep 29, 2009.

  1. #1
    I've been lurking for a while, but this is my first post. I'm a bit of a PHP newbie so please bare with me!

    I've created wordpress theme options for a link url and image url for a 468x60 ad in between the first and second post in my blog's homepage.

    The link URL is:
    $bbf_content_ad_link
    Code (markup):
    The image URL is:
    $bbf_content_ad_link
    Code (markup):
    I know these are functional because if I insert them in a basic anchor and place them directly in index.php, the ad shows up fine. Of course, if there is nothing entered in the fields on the theme options page, you get ugly X's in just about every browser besides Firefox.

    Basically, I'm trying to create a function in functions.php that will show the ad when I enter the link and url on the options page, but show nothing if the fields on the options page are left blank.

    Like I said, I'm a PHP newbie, so bare with me if this is horrible, but here's what I have so far:

    function content_ad() { ?>
    <?php if($bbf_content_ad_image) : ?>
    <a href="<?php echo $bbf_content_ad_link; ?>"><img src="<?php echo $bbf_content_ad_image; ?>"></a>
    <?php else : ?>
    <?php endif; ?>
    <?php }
    PHP:
    And in index.php I've got:

    <div id="content-ad">
    <?php if(!$show_ads){ ?>
    <?php content_ad() ?>
    <?php $show_ads = 1; } ?>
    </div>
    Code (markup):
    As I've got it set up, nothing is showing up. After a lot of google searching and forum searching, I'm a bit lost. Any help would be greatly appreciated!

    Adam
     
    AdamBaird, Sep 29, 2009 IP