Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   Adding AdSense to content (http://forum.bytesforall.com/showthread.php?t=431)

Jerry Feb 18, 2009 01:15 AM

Adding AdSense to content
 
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:)

Jerry Feb 18, 2009 09:43 AM

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?

Flynn Feb 18, 2009 02:12 PM

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?

Jerry Feb 18, 2009 02:59 PM

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!:)

Flynn Feb 18, 2009 03:51 PM

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 */
}


Jerry Feb 18, 2009 06:39 PM

Thanks Flinn, I'll see if I can get it done.;)

Jerry Mar 1, 2009 10:48 AM

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

Jerry Mar 1, 2009 11:16 AM

Sorry I guess a link to my blog would be a good idea.:)

Flynn Mar 1, 2009 01:38 PM

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

Jerry Mar 1, 2009 02:53 PM

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

Flynn Mar 1, 2009 03:44 PM

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?

Jerry Mar 1, 2009 08:53 PM

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?

Flynn Mar 2, 2009 03:43 AM

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() ) { 


Jerry Mar 2, 2009 05:54 PM

Thanks Flynn,
You rock!! Did you know that?:p

adum Jun 24, 2009 07:54 AM

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

Flynn Jun 24, 2009 10:28 AM

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

adum Jun 24, 2009 12:04 PM

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

Flynn Jun 24, 2009 01:19 PM

post #16 is for index.php, not functions.php

adum Jun 24, 2009 03:40 PM

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?

Flynn Jun 24, 2009 06:23 PM

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

adum Jun 24, 2009 07:08 PM

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?

Flynn Jun 24, 2009 07:21 PM

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

eadfrith Jul 6, 2009 03:47 AM

Quote:

Originally Posted by adum (Post 9093)
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?

adum Jul 8, 2009 10:14 AM

Quote:

Originally Posted by Flynn (Post 9084)
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.

juggledad Jul 8, 2009 11:23 AM

try using
HTML Code:

<?php if ( !is_single() AND !is_page() AND $postcount =< 2 ) { ?>


All times are GMT -6. The time now is 11:21 PM.

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