bbPress

Simple, Fast, Elegant

bbPress support forums » Themes

Google Adsense

(15 posts)
  • Started 1 year ago by ry4nanderson
  • Latest reply from geld_lenen
  • This topic is not a support question
  1. ry4nanderson
    Member

    Hello-
    I'd like to add some Adsense ads in either my header or below the the forum listing on the main page. Pasting Google's code in the header doesn't seem to play nicely. Any ideas? Sample syntax, perhaps, from those who have already done it?

    Thanks!

    Posted 1 year ago #
  2. I'd advise against using header.php, because your header is also shown on non-content pages such as 404's; something which is disallowed in the adsense T's and C's.

    I did it by writing a small plugin, which you're welcome to. Just create a my-plugins folder within your bbpress root folder, paste the text below into the file and save it as bbpress-adsense.php, upload it to your server and an advert will appear on every topic.

    From there on you have the basics for changing the advert to whatever you prefer.

    <?php
    /*
    Plugin Name: Simple bbPress Adsense
    Plugin URI: http://boakes.org/talk/tags/bbpress-adsense
    Description: An plugin that includes an adsense advert just above the content on the topic page.
    Author: Rich Boakes
    Version: 0.1
    Author URI: http://boakes.org
    License: GPL
    */
    class bb_adsense {
    function wide_advert() {
    ?>
    <div class="bbpress-adsense" style="text-align:center;">
    <!-- Paste your advert below this line -->
    <script type="text/javascript"><!--
    google_ad_client = "pub-9050338238897291";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text_image";
    google_ad_channel = "5984252204";
    google_color_border = "FFFFFF";
    google_color_bg = "EEEEEE";
    google_color_link = "990000";
    google_color_text = "333333";
    google_color_url = "999999";
    //--></script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <!-- Paste your advert above this line -->
    </div>
    <?php
    } // function wide_advert
    } // class bb_adsense
    // adds the footer so the javascript is loaded
    add_action('under_title', array('bb_adsense','wide_advert'));
    ?>

    Posted 1 year ago #
  3. I like this, but I want my adds to show AFTER each first post.

    So like:
    Post: Hi I need help bla bla
    google adsence
    First reply: do like this bla bla
    Sec reply: or like bla bla
    Etc

    How to do that?

    And is there also a page to maintain your adsence? Like how many click etc in the admin area?

    Greetz

    Posted 1 year ago #
  4. Hi Null, to do that you need to change your template a bit and create a new hook, which is dead easy, and a testament to the flexibility of the event model that underpins both WP&bb.

    1. Copy topic.php from bb-templates into my-templates (you may need to create this folder).
    2. Find the for loop near line 29 - it will read something like this: <?php foreach ($posts as $bb_post) : $del_class = post_del_class(); ?>
    3. Immediately before it (outside the loop, but inside the <?php) add the line $need_to_show_ad=true;
    4. Then change the line <?php bb_post_template(); ?> to read <?php bb_post_template(); if ($need_to_show_ad) { do_action('showadvert'); $need_to_show_ad=false; } ?>
    5. Finally, change the action in the plugin so it fires on your newly created hook add_action('showadvert', array('bb_adsense','wide_advert'));

    ... and an admin page? Maybe when bbPress matures!

    Posted 1 year ago #
  5. Jakey
    Member

    I almost understood that last part.

    -edit-

    oops! read it again and it made sense. thanks.

    Posted 1 year ago #
  6. When i post, edit or delete somethin i get this error
    Warning: Cannot modify header information - headers already sent by (output started at /home/disiern/public_html/enblogeo/foro/my-plugins/bbpress-adsense.php:39) in /home/disiern/public_html/enblogeo/foro/bb-includes/pluggable.php on line 160

    how can i solve this??

    Posted 1 year ago #
  7. Hi Disier, did you make any other changes other than add the plugin as above? Do you have other plugins installed? Which hook did you use (i.e. what does your add_action line say)?

    Posted 1 year ago #
  8. im using the latest version 0.75, and the only plugin the i have is allow image.

    I uninstalled right now because when my friend register in my board and try to login we get that error and can“t login i will delete allow image to see if that plugin is the one of the trouble

    Posted 1 year ago #
  9. Sorry I fix it the problem was here:
    a the end of the plugin
    <?php
    } // function wide_advert
    } // class bb_adsense
    // adds the footer so the javascript is loaded
    add_action('showadvert', array('bb_adsense','wide_advert'));
    ?>
    in the last line was needing an space after array('bb_adsense','wide_advert')); i dint give an space so the ?> was giving the problem thanks anyway

    Posted 1 year ago #
  10. Beer
    Member

    The add_action( 'under_title' .. ) part has me curious. Where does the 'under_title' come into play? I was trying to find it in my bbpress code. I want to add a wide 250x250 block for example under 'Add this topic to your favorites' on the left of the tags column.

    http://www.grindhouse.com/forums/topic/26?replies=1

    How can I accomplish this?

    Posted 1 year ago #
  11. jeremykuno
    Member

    This plugin causes an error when I try to delete users. I get the following message:

    Warning: Cannot modify header information - headers already sent by (output started at /home/jkuno/public_html/seattlecondoreport/forums/my-plugins/bbpress-adsense.php:43) in /home/jkuno/public_html/seattlecondoreport/forums/bb-includes/pluggable.php on line 168

    Any ideas?

    Posted 11 months ago #
  12. Look for blank lines or spaces before the starting <?php and after the ending ?> as they can cause that problem.

    Posted 11 months ago #
  13. Add google adsense code on each first post.

    http://www.articles2u.com/googleadsense/15-tips-for-improve-google-adsense-revenue/

    Posted 3 months ago #
  14. Articles2u, that are some good tips on that link, but I can't find a solution to the problem there! :(

    Posted 3 months ago #
  15. Can't get the system working on my blog, other colors?

    Posted 3 weeks ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.