Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme »

Adding AdSense to content


  #1  
Old Feb 18, 2009, 01:15 AM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
I would like to add AdSense top and bottom in with the content, and want to have single full posts show up from clicking on a list of links to them in the side bar.
I'm sure it's doable just wondering the easiest way to accomplish it.
I tried one of the AdSense plugins but the bottom of the ad block interfered with my post text.
I tried the add html, javascript box but didn't seem to work.
Thanks for your help I do appreciate it!
Jerry
  #2  
Old Feb 18, 2009, 09:43 AM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Hi again Flynn,
After reading more here http://forum.bytesforall.com/showthread.php?t=366 I thought I would quickly tell you I did donate (not much I'm unemployed like a lot of us in the USA) but I will donate for most every question I have in the future.
Maybe you should have a minimum donation required for you expertise?
  #3  
Old Feb 18, 2009, 02:12 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Jerry, I did not plan to ignore you. Your's requires a tad more thought and I only answered the quick easy questions the last 2 days. Thank you for the donation.

Where exactly do you want to place the Adsense (before, after title etc...)

The second part is not related to Adsense, right? It sound like you could just use the "Recent Posts" widget for that? A list of posts in the sidebar, and when you click on any link it goes to the single post page of that post? Or you don't want to show the recent posts, but specific posts?
  #4  
Old Feb 18, 2009, 02:59 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Hi Flinn,
Thanks for your response. I would like the ad block to be after the title and either above the content or within the top of the content on the left side.I got ads to show up using the "HTML/CSS inserts" box at the themes options page, but only above the header or below the footer, not within the content area.
My sites going to be an informational site about "natural health remedies and cures" and will have a lot of single post pages on each specific illness, so I want the ads to show up with the full post only, no summaries at all except perhaps in the feed.
I can put links to the pages via the the "text or HTML" widget although it would be nice if there was an easier way.
Thanks so much for your help. I don't have much experience working with HTML or CSS which was why I decided to use your theme, as well as it's good looks!
  #5  
Old Feb 18, 2009, 03:51 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
This should add an Adsense ad inside the top left of the post body on each single post page:

At the bottom of /atahualpa/functions.php add the following code, without adding/causing any blank line or blank space at the bottom of functions.php (or anywhere else in functions.php, outside of opening and closing PHP tags <?php ... ?>).
PHP Code:
<?php        
function bfa_add_adsense($post_body_content) {
    
$adsense_ad '<div class="bfa-adsense">
    PUT 
    YOUR 
    WHOLE 
    ADSENSE 
    CODE 
    HERE
    </div>'
;
    if ( 
is_single() ) {
        if (
strpos($post_body_content,'%adsense%')!==FALSE) {
            
$post_body_content str_replace('%adsense%'$adsense_ad$post_body_content);
        } else {
            
$post_body_content $adsense_ad $post_body_content;
        }
    }
    return 
$post_body_content;
}
add_filter('the_content''bfa_add_adsense');
?>
And at HTML/CSS Inserts -> CSS Insert, add:

HTML Code:
div.bfa-adsense {
float: left;
display: block;
margin: 1em 10px 5px 0; /* margin 1em top, 10px right, 5px bottom, 0 left */
}

Last edited by juggledad; Mar 19, 2010 at 06:55 AM. Reason: Fixed code, should work now
  #6  
Old Feb 18, 2009, 06:39 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Thanks Flinn, I'll see if I can get it done.
  #7  
Old Mar 1, 2009, 10:48 AM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Hi Flynn,
I finally got some pages done and decided to add the adsense block to it.
I think I did everything but don't see the ad. I'm pretty inexperienced with adding code and such so I may have done something wrong. Or perhaps it takes awhile for adsense to show up?
Anyway, when you get time-no hurry at all.
Thanks Flynn
  #8  
Old Mar 1, 2009, 11:16 AM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Sorry I guess a link to my blog would be a good idea.
  #9  
Old Mar 1, 2009, 01:38 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
I fixed the code above, and also expanded it a bit. Please try again.

It should add an ad into the top left of the post body on all single post pages.

Alternatively you can put %adsense% somewhere into a post and that placeholder be replaced with the Adsense ad (and the default top left ad won't be displayed)

To move the ad to the right, change
HTML Code:
float: left;
to
HTML Code:
float: right;
in the CSS Insert.

To put the default ad at the bottom (left or right) instead of the top (left or right) change, in the PHP code above

PHP Code:
$post_body_content $adsense_ad $post_body_content


to
PHP Code:
$post_body_content $post_body_content $adsense_ad
Default TOP or BOTTOM: Adjust PHP
Default LEFT or RIGHT: Adjust CSS
Alternative: Put %adsense% somewhere into the post. LEFT or RIGHT will still be adjusted by CSS
  #10  
Old Mar 1, 2009, 02:53 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Hi Flynn,
I put the amended code in and unfortunately the ads still don't show up.
Sorry Flynn, I can see you're putting a lot of time into this fix so another donation will be on it's way as I realize you aren't under any obligation to help all of us out, and I really do appreciate you're efforts on my behalf.
Again, I have very little experience, although it is just copy and paste, not too difficult.
Again no hurry, whenever you find the time.
Thanks
  #11  
Old Mar 1, 2009, 03:44 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
The above one is useful for me as well, my first attempt at an Adsense function so don't worry, since you've made a donation as well.

I tried the code and it worked for me. You know that a newly created Adsense code will take a while to display right? So there is not even a blank space for the Adsense ad?

I just checked your post here and see an ad

http://enaturesremedies.com/uncatego...st-to-see-adds

Did you add that differently?
  #12  
Old Mar 1, 2009, 08:53 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
No, but all my posts are on their own page. So if you open the page on "acne' or "pain management" I want the ads to show up there.
So I would imagine the same code will work if I just move it?
  #13  
Old Mar 2, 2009, 03:43 AM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
The above code shows ads on single post pages. To show them on "Page" pages as well, change
PHP Code:
if ( is_single() ) { 

to
PHP Code:
if ( is_single() OR is_page() ) { 
  #14  
Old Mar 2, 2009, 05:54 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Thanks Flynn,
You rock!! Did you know that?
  #15  
Old Jun 24, 2009, 07:54 AM
adum's Avatar
adum
 
85 posts · Jun 2009
Got a chance to read through this and it looks easy enough to implement. Well done.

Is there a way to make the ad only show up on the first post on the homepage (I can't have it show up on every post due to AdSense restrictions)?

Also, how would you make the Ad float in the center? Well actually I guess it wouldn't look good if it was centered with text around it, but maybe just plain centered? Would you do "align: center;" instead of float?

(Also, I made a small donation, it's not much but I know every bit can help and I plan to donate more later.)

Thanks,

Adam
  #16  
Old Jun 24, 2009, 10:28 AM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
In 3.3.3 you can put this:

<?php if ( !is_single() AND !is_page() AND $postcount == 1 ) { ?>
ADSENSE CODE HERE
<?php } ?>


above this:
PHP Code:
<?php // Post Container starts here
or below this:
PHP Code:
</div><!-- / Post --> 
in index.php
  #17  
Old Jun 24, 2009, 12:04 PM
adum's Avatar
adum
 
85 posts · Jun 2009
I hate to bother you more but I am receiving this error when I try to modify functions.php

Parse error: syntax error, unexpected '=' in ..../wp-content/themes/atahualpa/functions.php on line 691

This is not urgent, so please take your time responding if you have other things to do.

p.s. using 3.2, can upgrade if that is the problem

Last edited by adum; Jun 24, 2009 at 12:13 PM.
  #18  
Old Jun 24, 2009, 01:19 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
post #16 is for index.php, not functions.php
  #19  
Old Jun 24, 2009, 03:40 PM
adum's Avatar
adum
 
85 posts · Jun 2009
I know, I am referring to post #5. I will need the 2 codes from post #5 and the code from post #16 to make it work, right?
  #20  
Old Jun 24, 2009, 06:23 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
No, post #16 and #5 are different.

#16: Ad after first post on multi post pages

#5: Ad inside posts/pages on single post pages and/or static pages
  #21  
Old Jun 24, 2009, 07:08 PM
adum's Avatar
adum
 
85 posts · Jun 2009
Oh ok, my misunderstanding.

Is there a way to combine both of those? Ad on just first post with option of it being on page pages or not and positioned inside content?
  #22  
Old Jun 24, 2009, 07:21 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
You should be able to use both at the same time

If your Adsense code for post #5 contains single quotes ' then you'd have to "escape" those by putting a back slash in front of each single quote \' inside your Adsense code
  #23  
Old Jul 6, 2009, 03:47 AM
eadfrith
 
1 posts · Jul 2009
Quote:
Originally Posted by adum
I hate to bother you more but I am receiving this error when I try to modify functions.php

Parse error: syntax error, unexpected '=' in ..../wp-content/themes/atahualpa/functions.php on line 691

This is not urgent, so please take your time responding if you have other things to do.

p.s. using 3.2, can upgrade if that is the problem
I am having the same issue - also using 3.2. Did you ever find a solution for this?
  #24  
Old Jul 8, 2009, 10:14 AM
adum's Avatar
adum
 
85 posts · Jun 2009
Quote:
Originally Posted by Flynn
In 3.3.3 you can put this:

<?php if ( !is_single() AND !is_page() AND $postcount == 1 ) { ?>
ADSENSE CODE HERE
<?php } ?>


above this:
PHP Code:
<?php // Post Container starts here
or below this:
PHP Code:
</div><!-- / Post --> 
in index.php
1. To make the ad appear for the 1st and 2nd posts, how would I change the code?

2. This code will make the ad appear on the homepage along with the multi and single post pages, correct?

3. I originally had my script placed directly above
PHP Code:
</div><!-- / Post --> 
, not below it, so is this a problem? I wanted the ad to appear directly below the footer and it shows up fine, but if I want to limit the number of times it shows up is this going to be an issue? If I move the code outside those restraints, where will the ad show up?

eadfrith: I never did figure it out, I plan to mess with the code some more today.

Last edited by adum; Jul 8, 2009 at 10:41 AM.
  #25  
Old Jul 8, 2009, 11:23 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
try using
HTML Code:
<?php if ( !is_single() AND !is_page() AND $postcount =< 2 ) { ?>
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support

Bookmarks

Tags
adsense



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Adsense to Kicker and Content adum Post-Kicker, -Byline & -Footer 2 Jun 22, 2009 09:29 AM
Turn off AdSense on certain pages Jerry Atahualpa 3 Wordpress theme 1 Apr 4, 2009 04:34 PM
AdSense Question Jerry Atahualpa 3 Wordpress theme 1 Feb 21, 2009 04:24 AM
How do I insert an Adsense ad after the first post on the page only? jonco Atahualpa 3 Wordpress theme 2 Feb 15, 2009 09:24 AM
Adsense code in Text widget jonco Sidebars & Widgets 5 Feb 11, 2009 04:18 PM


All times are GMT -6. The time now is 04:03 AM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.