Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   [SOLVED] Add Adsense section targeting code to single.php (http://forum.bytesforall.com/showthread.php?t=11257)

Stefan72 Nov 19, 2010 06:02 AM

[SOLVED] Add Adsense section targeting code to single.php
 
Another thread on the forum mentioned adding the code immediately below to the index.php as there is no single.php

<?php if ( is_single() ) { ?>
YOUR CODE HERE
<?php } ?>

The code I need to add is

<!-- google_ad_section_start -->

<!-- google_ad_section_end -->

In the middle of Google's 2 lines of code I also need to have the code that relates to the entire content of each post. I am new to coding and know it should look something like the_content() but not sure exactly.

Can you tell me what code in its entirety I need to add to index.php and where exactly I should put it?

Thanks very much.

juggledad Nov 19, 2010 06:17 AM

What version of Atahualpa and WP?
You should add it in the option at ato->Style & edit CENTER COLUMN->Content ABOVE the LOOP

Stefan72 Nov 19, 2010 06:33 AM

Thanks for your reply. I'm using Atahualpa 3.5.3 and WP 3.0.1

Do I add the code below the code that is currently showing in the above the loop box, or is there anywhere else I should be putting it?

Would you mind listing the exact code I should be adding? Would it be,

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
<?php the_content(); ?>
<!-- google_ad_section_end -->
<?php } ?>

Thanks again

juggledad Nov 19, 2010 07:26 AM

HTML Code:

<?php if ( is_single() ) { ?>
<!-- google_ad_code -->
<?php } ?>

using this would only show the ad on a page that was a single post. Is that what you want?

Stefan72 Nov 19, 2010 07:38 AM

Yes, I just want it in single posts, but I've already got the actual ad code embedded in specific posts, by copying it to the html view of the edit post screen in wordpress.

I'm told I just need this extra bit of coding, in theory to the single.php file, that tells google to focus adsense ads on the content of each post only, rather than all the text visible on any given page e.g. the site title, sidebars and so on.

Google's advice - see https://www.google.com/adsense/suppo...n&answer=23168 - suggests using the 2 bits of code like this, but where it says "This is the text of your webpage. Most of your content resides here," I'm not sure what you'd replace it with for Atahualpa.

<html><head><title>Section targeting</title></head>
<body>
<!-- google_ad_section_start -->

This is the text of your webpage. Most of your content resides here.

<!-- google_ad_section_end -->
</body>
</html>

Stefan72 Nov 19, 2010 11:58 AM

Hi again,

Should I be putting this code as the last bit of code in the above the loop box?

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
<?php the_content(); ?>
<!-- google_ad_section_end -->
<?php } ?>

Is the <?php the_content(); ?> bit in the middle correct?

Thanks

juggledad Nov 19, 2010 01:13 PM

You should probably put the start in the above the loop section, and the end in the below the loop section

Stefan72 Nov 19, 2010 02:45 PM

Sorry, just to be clear,

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
<?php the_content(); ?>

in the above the loop, and

<!-- google_ad_section_end -->
<?php } ?>

in the below the loop, or something else?

Thanks

juggledad Nov 19, 2010 03:32 PM

I don't think you want the line the_content() at all, the loop will be providing the content. You should also check for the is_single() for the closing ad code. Don't forget that you will have to wrap the bottom part in the <?php

Stefan72 Nov 19, 2010 03:49 PM

Hi again,

Hopefully almost there. I put,

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->

in above the loop box at the end of the rest of the code, and

<!-- google_ad_section_end -->
<?php } ?>

in below the loop box again at the end of the rest of the code but got this error,

Parse error: syntax error, unexpected $end in /home/stefan01/public_html/wp-content/themes/atahualpa353/functions.php(532) : eval()'d code on line 8

Do you know what I did wrong. Sorry if I misunderstood your last reply but very new to this stuff. If there's any chance you could spell out to me exactly what code I need to put where, I'd be very grateful.

Thanks...

juggledad Nov 20, 2010 05:07 AM

HTML Code:

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
?>

same for the end

Stefan72 Nov 20, 2010 12:47 PM

Hi,

Added the code as follows,

above the loop right at the end of the rest of the code:

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
?>

below the loop right at the end of the rest of the code:

<?php if ( is_single() ) { ?>
<!-- google_ad_section_end -->
?>

but got this error...

Parse error: syntax error, unexpected $end in /home/stefan01/public_html/wp-content/themes/atahualpa353/functions.php(532) : eval()'d code on line 9

Do you know if there's anything else I could try. Thanks very much.

juggledad Nov 20, 2010 01:16 PM

you can't have an open '{' with out a close '}' - it seems like you need to learn some php and HTML so you know how to add things like this. you have
HTML Code:

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
?>

The '<?php' switches you into php syntax, then you have the
HTML Code:

if ( is_single() )
that is the if statement and if conditional.

Next comes true section. If you have more than one statement, they need to be in {...}, with just one true statement you can ignore the {}. But since you have the opening '{' that is what starts the true statement. In order to use HTML in thresult, upi have to switch oout of PH and so you have teh '?>' to do it. This is followed by the html google statement
HTML Code:

<!-- google_ad_section_start -->
followed by a '?>' - this is invalid since you are trying to switch back to HTML mode, but you are in it...and you need the closing '}' so you must code
HTML Code:

<?php }; ?>
I would suggest taking some time to learn some basic HTML, CSS and PHP if you are going to be adding anything more to your site

Good luck

Stefan72 Nov 24, 2010 05:58 AM

Thanks, it looks like that has worked.


All times are GMT -6. The time now is 07:18 AM.

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