Recent Topics

1 Mar 12, 2004 22:45    

I've just been accepted in to Google Adsense, but I'd rather not plaster them all over my site. I'd like to display them above the date only on the permalink URLs, but can't work out how to make them not display in the main view. Can anyone point me in the right direction please?

Thanks
Stuart

2 Mar 16, 2004 22:44

Stuart,

Try this:

<?php if($more) { ?>Google Stuff Goes Here<?php } ?>

3 Mar 17, 2004 07:19

isaac wrote:

Stuart,

Try this:

<?php if($more) { ?>Google Stuff Goes Here<?php } ?>

When checking for the existance of string it's better to use the isset() function.

i.e.

<?php if(isset($more)) { ?>Google Stuff Goes Here<?php } ?>

4 Mar 17, 2004 07:59

No, just using if($more) is better - you only want to show the ad on a page which actually is displaying the full text (ie. &more=1), not anything else (&more=0).

-Vegar

5 Jun 24, 2004 00:26

Nowadays, (0.9x, that is) "more" isn't the best thing to use here. Try this:

<?php if($disp != 'posts') { ?>Google Stuff Goes Here<?php } ?>

6 Jun 07, 2005 14:53

I know this thread is terribly old but if anyone is still getting this... ;)

Concerning the above code, is that in the _main.php? Thanks

7 Jun 07, 2005 15:42

Yeah, put it in _main.php, or whatever skin template you're putting your google adsense stuff in.

For example, you could have include( dirname(__FILE__) . '/_googleadsense.php'); in your _main.php, and then put the google adsense code in _googleadsense.php, or something like that.

8 Jun 07, 2005 15:45

Hey thanks for the quick reply. I've already got some code for my sidebar calling google adsense. Just to clarify, I'm hoping to have this second adsense code added into the body of the posts. I'm guessing _main.php isn't the right file for that...

9 Jun 07, 2005 16:13

_main.php is the main file that all skins use. It includes any other files. If you look through that template, you'll see sections for various things, like posts, sidebar stuff, etc.

That's the right file. Play around with it. Have fun.

10 Jun 07, 2005 16:34

Got it to work perfectly. I just needed to take a closer look at the code. Thanks!

12 Jun 28, 2006 15:56

Hi again
I look for whole forum but I did not find my answer
my problem is that: I can not locate google adsense code to main.php
would you explain step by step how can I put adsense code to main.php
( I use costum skin )
please help

13 Jun 29, 2006 08:08

Actually I have been trying to place Adsense on my blog, but even though I followed the instruction in this forum, I don't succeed it yet. So I'm wondering why it doesn't show up. If anyone helps me do it, it would be really appreciate it.

I'm trying to place Adsense under each post. The following is my code.



		<h3 class="bTitle"><?php $Item->title(); ?></h3>
		<div class="bText">
			<?php $Item->content(); ?>
			<?php link_pages() ?>


<script type="text/javascript"><!--
google_ad_client = "pub-6748064943973405";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


		</div>


		<div class="bSmallPrint">

15 Jul 20, 2006 17:19

Why didn't you post this in that topic?

16 Jul 20, 2006 17:33

balupton wrote:

Why didn't you post this in that topic?

I get this question all the time!

Answer: Because thats the way I did it. :lol:

ps. My wife hates this answer...

17 Jul 20, 2006 19:00

Merged. A tidy forum is a happy forum!

As far as I know, it is impossible to include adsense in the body of a post. The post content (or body of the post) is pulled from the database, rendered according to whatever renderers are active, then served up as page content. Having javascripts IN the post will choke b2evolution. This is my understanding though others have successfully tricked their way past some details here.

The code you copied

<?php if($disp != 'posts') { ?>Google Stuff Goes Here<?php } ?> 

would put the adsense stuff on single post pages. Not in the body of each post, and not in the body of the post on the single post page. To make it work you'd do something like this in your skin's _main.php file:

<div class="bPost" lang="<?php $Item->lang() ?>">
	<?php
		locale_temp_switch( $Item->locale ); // Temporarily switch to post locale
		$Item->anchor(); // Anchor for permalinks to refer to
	?>

<?php if( $disp != 'posts' ) { ?>
the javascript stuff 
google gives you 
to paste in
<?php } ?>

	<div class="bSmallHead">

------------

This could be a plugin or renderer, even in the 0.9.2 days. I THINK it could be a plugin is what I mean. Like you add something like

<!-- adsense-code-renderer -->

via a button and the render then replaces that with all the googly stuff. Dunno if it's been done for 0.9.2 but I'm pretty sure someone is working towards that goal for the 1.8 package.

18 Jul 20, 2006 20:05

Thanks for responding!

My goal is to have the ability to manually add the Adsense code into the body of individual posts.

It would be way to risky to add the code into every post automatically, as you would end up violating the Google publisher guidelines TOS by having way too may instances of Adwords. Besides being extra ugly!

So I am back to this piece of code – how to make it work?

<?php if($disp != 'posts') { ?>Google Stuff Goes Here<?php } ?>

Thanks again, and I will attempt to be more tidy in the future.

DEL

19 Jul 20, 2006 21:25

That code won't do what you want. It will put google ads on single post pages outside the body of the post. To put an ad inside a post, and to have control over exactly which posts and where within the post, will require a plugin that doesn't exist.

Tell ya what: I'll see about doing a plugin for 0.9.2 even though it's boring to work on the old stuff and you think about upgrading to the 1.8 release. 1.8 is a beta release and there are a couple of known issues that will be fixed with 1.8.1, but no one knows when 1.8.1 will happen and you'll find a lot more people doing a lot more groovy plugin stuff with 1.8 than 0.9.2.

Assuming I can do this plugin you'll have to be the tester because I don't have all the groovy code it takes to put adsense on my web(s). I don't do adsense, and the plugin will contain bogus info about your ads is why. Someone will have to test the plugin by editing it and adding real official adsense values that google gave them.

Plus it might not work anyway ;)

20 Jul 20, 2006 21:29

I recall finding a way to automatically add the Adsense code to each post by messing with a PHP file.

HOWEVER

It was a futile effort, as the Adsense code prevented any more than 3 ads on a page at once. I imagine even if there was a way to add javascript to a single B2 post, you would be limited to seeing 3 ads.

21 Jul 20, 2006 22:18

There's a hack (somewhere) on the forums that will spit out adsense after every ## posts (per page). It really wouldn't take much to limit it to "+ max number of ads to spit out".

When I get chance I'll see if I can find it for you.

If I was you I wouldn't listen to that EdB geezer, he thinks throwing himself at the ground with an "I'm sure I'll miss this time" attitude is fun :|

¥

22 Jul 20, 2006 22:35

I am willing to test away! I figured this was an easy issue, and I was just too slow to figure it out.

Upgrade ... I just upgraded to 0.9.2 LOL Please tell me I will be able to keep my skin mods.

Thanks All - DEL

23 Jul 20, 2006 23:00

Slightly Off Topic (but since I brought it up...)

Upgrading skins from 0.9.2 to 1.8 isn't as easy as going from any previous version up to 0.9.2. There is a page in the wiki manual about it at http://manual.b2evolution.net/Upgrade_Skin_from_0.9.2_to_1.8 if you're inclined to go that way. BTW I'm just about done with a 'best guess' plugin so if you want to hang with 0.9.2 for a bit I think I'll be able to get you going.

-------------------

As ¥åßßå correctly points out, somewhere in the forums is a way to do this for every X number of posts. The thing is I don't think it was done to put the ads INSIDE a post. Between the title and the post is common - and easy. Before or after the title on single post pages is common - and easy. This second method is what the code you asked about does. Inside the post is just another renderer. I think!!!

As ¥åßßå incorrectly points out, I always expect to return to the surface. The thing I hope for is to live through the experience :lol:

24 Jul 21, 2006 02:31

Re Adsense and putting it in every post..... if you show more than 2 posts on any page you might want read the Adsense Terms and Conditions about the number of Ad's allowed per page.

The code for putting an Adsense ad in _main.php and have it appear after the first post on any page is..

<?php
    if ( ! $shown_advert )
    {
?>
Google Adsense Goes Here
<?php
      $shown_advert = 1;
    }

}
 // ---------------------------------- END OF POSTS ------------------------------------ ?>


may give you something to play with.


Form is loading...