|
#26
Jul 8, 2009, 01:04 PM
|
|
Thanks juggledad. I knew it was something pretty obvious but I am bad at coding.
I guess I'll see if everything works and report back, my blog is just underway and has post scheduled every day for the next week or so but I only have one post up so far, so I'll be able to tell in a few days.
|
#27
Jul 8, 2009, 01:59 PM
|
|
errr I have a problem already. I moved the script outside the post div and it is still in the same spot which is good, but when I put the php code around it, I had some issues.
When I clicked on the post title, it took me to a totally blank page. Same when I clicked on the categories. When I removed the php from the code everything worked fine again. Not really sure about this...
|
#28
Jul 9, 2009, 11:05 AM
|
|
Quote:
Originally Posted by juggledad
try using
HTML Code:
<?php if ( !is_single() AND !is_page() AND $postcount =< 2 ) { ?>
|
I tried using the code with $postcount == 1 and the blank page error went away. The ad does not show up on the single post page however, which I would like. It does show up after the first post on the homepage and on multipost pages (categories and archives). (Also does NOT show up on pages.)
I feel like the blank page error might have arisen because there is only one post on single post pages?
If it is possible to get the ad to appear on single post pages as well, I would like to know how to do that.
If there is a fix to get the ad to appear below the first TWO posts without getting the blank page error, that would be great too but I can live with it being below just the first post.
|
#29
Jul 9, 2009, 11:31 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
Try this
HTML Code:
<?php if ( is_single() or (is_page() AND $postcount =< 2) ) { ?>
ADSENSE CODE HERE
<?php } ?>
or in english, if this is a single post page do it, if it is a multi post page, do it for the first two posts.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#30
Jul 9, 2009, 12:08 PM
|
|
I kept getting blank pages when I used "=<" but I got this to work:
PHP Code:
<?php if ( is_single() or (!is_single() AND !is_page() AND $postcount == 1) or (!is_single() AND !is_page() AND $postcount == 2) ) { ?>
Thank you so much for the help, I promise to donate to you in the near future when I have some money.
|
#31
Jul 24, 2009, 07:30 PM
|
|
Quote:
Originally Posted by Flynn
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 */
}
|
Is adding this different from 3.4.1? I get errors every time I try to add it and have to upload a clean functions php file to get wordpress working again.
|
#32
Jul 24, 2009, 08:19 PM
|
|
|
|
3,768 posts · Oct 2008
Munich, Germany
|
|
Which errors?
|
#33
Jul 27, 2009, 08:47 AM
|
|
Man I forget exactly, but it was something like a white page with just a line of text at the top that said "Unexpected "=" found at line 587". I could reproduce the error if you would like specifics.
|
#34
Jul 28, 2009, 11:26 AM
|
|
I get this error too.. the exact error is:
Parse error: syntax error, unexpected '=' in /var/www/MY SERVER PATH HERE/blog/wp-content/themes/atahualpa/functions.php on line 532
|
#35
Aug 6, 2009, 02:51 PM
|
|
|
|
3,768 posts · Oct 2008
Munich, Germany
|
|
Make sure you aren't closing the single quotes that wrap the adsense code, pre-maturely:
adsense_ad = '<div class="bfa-adsense">
PUT
YOUR
WHOLE
ADSENSE
CODE
HERE
</div>';
If you have single quotes inside your code, you'll need to escape them by putting a backslash in front of them. You don't need to escape double quotes:adsense_ad = '<div class="bfa-adsense">
PUT
YOUR
\'WHOLE\'
ADSENSE
"CODE"
HERE
</div>';
or wrap your code into double quotes instead of single quotes. In that case you need to escape double quotes, if you have any:
adsense_ad = "<div class="bfa-adsense">
PUT
YOUR
'WHOLE'
ADSENSE
\"CODE\"
HERE
</div>";
|
#36
Aug 10, 2009, 08:45 AM
|
|
If anyone out there is interested, I ended up using a Plugin called "Advertising Manager" to get the ad in the content. It's pretty simple to use.
One more question tho...I am editing the center column and if I want something to show up on multi post pages, EXCLUDING the homepage/frontpage, how would I go about that?
|
#37
Aug 10, 2009, 09:18 AM
|
|
hi Flynn,
Don't mean to hijack this thread but, I can't seem to find the code in the forum on how to add the adsense code on the sidebar. I have been browsing through the forum and I can't seem to find the exact way to insert adsense code on the sidebar. Any help would appreciated. thanks a lot!
Em
http://techsupporthelp.web44.net
|
#38
Aug 10, 2009, 10:20 AM
|
|
finaldata,
I use a plugin called "Advanced Text Widget". I don't even think you need that, but just insert the script google gives you into a text box on your sidebar. You have to drag the text box over on the "widgets" page and then put the code in there and hit save.
|
#39
Aug 18, 2009, 04:46 PM
|
|
I obviously did something very wrong.
I entered the code as you posted, but I thought I was supposed to enter it outside the php ?>
Now I get this:
Parse error: syntax error, unexpected '=' in /home/collette/public_html/MYSITE.com/wp-content/themes/atahualpa342/functions.php on line 553
I'm locked here. I can't get into my WP dashboard to undo the change.
HELP!!!
|
#40
Aug 18, 2009, 05:37 PM
|
|
So I edited the file in cPanel, and that "seemed" to fix the problem.
But now, when I go into WP admin, I get this at the top of every screen:
Warning: Cannot modify header information - headers already sent by (output started at /home/collette/public_html/MYSITE.com/wp-content/themes/atahualpa342/functions.php:553) in /home/collette/public_html/MYSITE.com/wp-includes/functions.php on line 784
Warning: Cannot modify header information - headers already sent by (output started at /home/collette/public_html/MYSITE.com/wp-content/themes/atahualpa342/functions.php:553) in /home/collette/public_html/MYSITE.com/wp-includes/functions.php on line 785
Does anybody have ANY idea what's going on here? I didn't touch the header!
Added: and when I try to reset the page options using the admin panel, I get a blank page with the same two messages.
Update: Deleted and re-uploaded the whole thing. Still have no idea what happened.
Last edited by Little Red; Aug 18, 2009 at 07:37 PM.
|
#41
Aug 22, 2009, 10:21 PM
|
|
|
|
3,768 posts · Oct 2008
Munich, Germany
|
|
Header already sent usually means that there is a blank line at the bottom of functions.php
|
#42
Aug 29, 2009, 01:28 PM
|
|
this plugin solves all the adsense problems - it's great:
Whydowork Adsense
If you're working with wordpress, you can just upload it. Otherwise, just google for it. I can put adsense just about anywhere I want.
|
#43
Sep 6, 2009, 04:30 PM
|
|
|
3 posts · Sep 2009
Sweden
|
|
Hi,
(My first post - I'm a new blogger with some programming experience. I love the theme and the active support on the forum.)
I have the same problem as adum #33 and river #34 above - when I make the addition to functions.php things get messed up:
Parse error: syntax error, unexpected '=' in /home/MYUSERNAME/public_html/MYBLOG/wp-content/themes/atahualpa/functions.php on line 533
Here's a part of my functions.php with line numbers added:
PHP Code:
531 <?php
532 function bfa_add_adsense($post_body_content) {
533 adsense_ad = '<div class="bfa-adsense">
534 <script type="text/javascript"><!--
[...the rest of the Adsense code as provided by Google]
545 </div>';
546 if ( is_single() ) {
[...the rest of the code provided by Flynn in #5]
556 ?>
The thing is, even with
PHP Code:
531 <?php
532 function bfa_add_adsense($post_body_content) {
533 adsense_ad = 'foo';
534 if ( is_single() ) {
[...the rest of the code provided by Flynn in #5]
the result is the same.
However, if I skip the assignment it won't result in an error:
PHP Code:
531 <?php
532 function bfa_add_adsense($post_body_content) {
533 if ( is_single() ) {
[...the rest of the code provided by Flynn in #5]
But then again, it won't present any ads either...
I guess this is why I never will be a great programmer, there is nothing that makes me as frustrated as this.
|
#44
Sep 14, 2009, 04:35 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
try this
HTML Code:
533 $adsense_ad = '<div class="bfa-adsense">
note the '$' sign
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#45
Sep 18, 2009, 12:49 PM
|
|
I am also experiencing the problem with "parse error" when I try to modify functions.php. I have just upgraded to Atahualpa 3.4.1. When I put in the code (exactly as shown without any spaces, etc., or modifications to anything else), it breaks my blog. I couldn't even get into wp-admin to fix anything. Thank goodness I backed up my complete folder that holds my blog via FTP. I tried another suggestion to delete the Atahualpa folder from themes (which it was said should default back to default template), but my blog was still not showing. The only thing that worked was to re-upload via FTP my saved blog folder and overwrite the contents. I am not asking for any help with this, I just wanted to add in that I have experienced the same problem. The really frustrating thing is that I copied and pasted the contents of functions.php into a notepad, in case the added code caused a problem, so I that I could copy/paste back in EXACTLY what was there originally and it didn't help. I even went to another blog I have that uses atahualpa and copied out the functions.php but no dice. The only thing that worked in the end was to re-upload my saved blog folder. I've already deleted and re-uploaded twice today, guess I'll be waiting on getting Adsense to the byline area of my single posts.
|
#46
Sep 18, 2009, 01:09 PM
|
|
BTW, I decided to try the Whydowork Adsense plug-in. I have it working now, it was very easy to install. Just be sure you click on "show adsense to administrator" while working on it, or you won't be able to see if it's working!!
|
#47
Feb 5, 2010, 07:33 PM
|
|
Quote:
Originally Posted by Flynn
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 */
}
|
Finally figured this out...
PHP Code:
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');
That's what you gotta at the very end of functions.php, right before . Customize the CSS as Flynn said.
I put some extra conditions, to only put these ads in the content if the post is over a month old. I did that with this:
Replace
PHP Code:
if ( is_single() )
with
PHP Code:
if ( !is_page() AND is_single() AND (current_time(timestamp) - get_the_time('U') -
(get_settings('gmt_offset')))/(24*60*60) > 30 )
hope that helps!
|
#48
Mar 2, 2010, 10:12 AM
|
|
Hi all!
I'm new to this theme and this is my first post in thes forum. I'm trying to add Adsense to the home page of my blog. I don't like to use a plugin for Adsense, and I've added the code to functions.php plus that little piece of code in CSS inserts, and that's working great for posts.
I've tried some of the suggestions here, but can't get anything to work. I did get Adsense to show up on pages, which I don't want. I just want it to be on single posts and the home page.
Any advice is greatly appreciated!
|
#49
Mar 4, 2010, 05:14 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
This post was originally opened when Atahualpa waas at version 3.2 - it's now at version 3.4.6 with some major changes. One of them is the option 'The LOOP' in the 'Style & edit CENTER COLUMN' area.
you can do all sorts of things here and pretty muck eliminate most of the changes to the code (like function.php) and save yourself having to make those changes again at the next release.
By putting in some simple php logic in the 'Content ABOVE the LOOP' you could have your AD show up at the top of the center area before the posts
HTML Code:
<?php if (is_single() or is_front_page()) { ?> <div class="bfa-adsense">
PUT
YOUR
WHOLE
ADSENSE
CODE
HERE
</div>
<?php }; ?>
should be all you would need. This way the code is stored as one of the Atahualpa options in the DB and will not need to be changed during an upgrade.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
Last edited by juggledad; Jun 10, 2010 at 06:19 AM.
Reason: fixed the error in the example code
|
#50
Mar 19, 2010, 08:04 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
NOTE: if you got the error
HTML Code:
Parse error: syntax error, unexpected '=' in /home/djembata/public_html/formula1/wp-content/themes/atahualpa/functions.php on line 669
(the line number could be different) make sure the variable 'adsense_ad starts with a '$' si it was
HTML Code:
adsense_ad = '<div class="bfa-adsense">
make sure it looks like this
HTML Code:
$adsense_ad = '<div class="bfa-adsense">
I fixed it in the post #5
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
|