WordPress.org

Ready to get started?Download WordPress

Forums

Plugin/Shortcode to post specific ads on specific pages? (3 posts)

  1. whattheydontsay
    Member
    Posted 2 years ago #

    Looking for an ad management program that will let me insert a shortcode into sidebar.php... let's say it's called [adGoesHere]. Then in the admin side I could upload the image, type in the link and specify the page for it to show up on. So ad_001 would only show up on About Us, ad_008 would only show up on Services, etc.

    Anything like that already exist? I've been hunting but can't seem to find anything like it. My only other option seems to be custom templates but that'd be a pain for my client to maintain.

    Thanks in advance.

  2. Marventus
    Member
    Posted 2 years ago #

    Hi there,

    You don't really need a plugin to accomplish this. You can do it yourself through some of WP's default functions.
    Here is how I would do it:
    1. Add a custom self-enclosing shortcode function through the WordPress Shortcode API, which would have an 'add_number' argument, so you could call any of your ads like this:

    [adGoesHere ad_number="1"]

    2. If you don't already have them, install Exec-PHP and Role Manager plugins. The first one allows you to run PHP code in your posts, pages, and widgets, and the second one controls which users have PHP execution capabilities (for security). There are many role and capability managing plugins out there, so if you already have one, just use that one.

    3. Create a new widget in your sidebar and use php multiple if statement to call the ads depending on the location. Some examples:

    <?php if ( is_home() ) {
    echo '[adGoesHere ad_number="1"]';
    }
    elseif { is_category('6') ) {
    echo [adGoesHere ad_number="2"]';
    } else {
    }
    ?>

    For is_category, you should replace the value 6 with the value of the category for which you want the Ad displayed. If you don't know how to implement any of this, let me know and I'll walk you through it.
    Cheers!

  3. Marventus
    Member
    Posted 2 years ago #

    Hi,

    Were you able to figure this out? If so, could you please mark this topic as resolved?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic