WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add advertisement after first post? (19 posts)

  1. bboy131
    Member
    Posted 4 years ago #

    I have been trying to figure this out forever now. I have found a lot of sites that say "Hey just insert this code into your index.php file" but the problem is Mystique does not have the code they say is suppose to be there.

    I want to insert an Adsense block after the first post on homepage/pages.

    The code they gave me was

    <?php if(!$show_ads){ ?>

    [advertisement goes here]

    <?php $show_ads = 1; } ?>

    But that doesn't work. Any ideas?

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    so, what does not work?

    where did you insert this code?

    and did you replace [advertisement goes here] with your adsense code?

    this code snippet with your own adsense code in the middle should be inserted into index.php before the line with <?php endwhile; ?>

  3. digitalnature
    Member
    Posted 4 years ago #

    go to mystique settings > advanced and in the 'functions' field add:

    <?php
    
    function my_ad_plugin(){
     if(is_home()){
       if(!$show_ads){
        ?>  [advertisement goes here] <?php
        $show_ads = 1;
       }
     }
    ]
    
    add_action('mystique_after_post', 'my_ad_plugin');
    ?>

    but I wouldn't use plugins for this if I were you. mystique already has ad management features trough shortcodes...

  4. bboy131
    Member
    Posted 4 years ago #

    @alchymtyh the ad does not show at all. My index.php file does not have a <?php endwhile; ?> in it or anything about posts. My page.php does and that file affects the homepage. So I cannot insert the code on index.php

    @digitalnature I added the code you provided and it highlights the last part in red and gives me an error when I load my website

    I don't understand why this isn't working. Should be simple lol

  5. digitalnature
    Member
    Posted 4 years ago #

    there's a mistake above, replace ] with }.

    here's another way, without any plugin:

    <?php
    function my_ads(){
      global $ads_already_displayed;
      if(is_home())
       if(!$ads_already_displayed){
        $ads_already_displayed = 1;
        echo do_shortcode('[ad code=2]');
       }
    }
    
    add_action('mystique_after_post', 'my_ads');
    ?>

    to set up the ad go to the ads tab and paste your adsense code or whatever in #2

  6. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #


  7. bboy131
    Member
    Posted 4 years ago #

    Alright I added the php code you provided into the Advanced section. Sometimes Adsense takes a while to show new ads, so I will let you know if it worked. Thanks for the help

  8. bboy131
    Member
    Posted 4 years ago #

    It still doesn't show up...GAH! It makes no sense. I have tried everything. Makes me feel like a WP newb even though I have been using it for a long time

  9. digitalnature
    Member
    Posted 4 years ago #

    replace the adsense from ad code #2 with some dummy text and see if it shows up.

  10. bboy131
    Member
    Posted 4 years ago #

    Replaced with text and still not showing that. Hmmm

  11. digitalnature
    Member
    Posted 4 years ago #

    are you using mystique 2+ ?

  12. bboy131
    Member
    Posted 4 years ago #

    No unfortunately I had some problems with trying to upgrade to the newest theme. When I upgraded to the newest, I had some CSS issues, so I kept version 1.72.

    I want to upgrade to the newest but I'm afraid of screwing up all of my editing on this template so I am just leaving it at the current 1.72 version.

  13. bboy131
    Member
    Posted 4 years ago #

    This problem isn't a huge deal. I can just live without it I guess.

  14. bboy131
    Member
    Posted 4 years ago #

    To upgrade to the newest version, do I just remove the old theme folder and upload the new one? So I will have to redo the changes I want in the new theme.

  15. digitalnature
    Member
    Posted 4 years ago #

    yes.

    I would advise you not to make changes to the theme files in the future. The 'functions' and 'user css' options should be enough to make any modifications you want to the theme, without loosing them in updates

  16. bboy131
    Member
    Posted 4 years ago #

    This theme is awesome but it seems to hate me lol.
    I upgraded to the newest 2.2 theme and now my sidebar titles are messed up.
    I put the link so you can see, the widgets are missing the header block backgrounds. I've removed and added widgets again but no go.

    http://img98.imageshack.us/img98/5721/mystique.png

    Sorry for all the bugging

  17. digitalnature
    Member
    Posted 4 years ago #

    yes, upgrading from 1.7 to 2.x can go wrong since most of the code has been changed in 2.0

    try this:
    - disable any cache plugins
    - delete the old theme, the upload the new one
    - refresh the homepage, enable back the cache plugins

    if this still doesn't fix the problems, press the "reset settings" button from the theme settings. make sure you save any code you have there before you do that

  18. bboy131
    Member
    Posted 4 years ago #

    That worked. Plugin was causing problems. I will upgrade and use the previous code you gave me above. Thanks for the help!

  19. mikelangel001
    Member
    Posted 3 years ago #

    Hello DigitalNature this question goes to you.

    I have a blog (patataloca.net) with the theme mystique. I used the following code to put an adsense block below the first post.

    <?php
    function my_ads(){
      global $ads_already_displayed;
      if(is_home())
       if(!$ads_already_displayed){
        $ads_already_displayed = 1;
        echo do_shortcode('[ad code=1]');
       }
    } 
    
    add_action('mystique_after_post', 'my_ads');
    ?>

    So far, so perfect, but I also want to put a adsense block on post number 8 for example. What would you change or add to show me the adsense below the first post (as I had) and also in the eighth?

    Sorry if I'm not well understood, but I am Spanish and my English is not perfect.

    Thank you very much and hope you can help.

Topic Closed

This topic has been closed to new replies.

About this Topic