Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-12-08 18:59:29

adamtal
Member
Registered: 2006-09-14
Posts: 25

Google Adsense inside an article?

I’m trying to figure out a way to automatically add the AdSense code into all articles on my site, somewhere in the article, for example, after X words/lines/sentences, etc.

any ideas on how would i do that?

Please note: Newbie here… please don’t assume to much about my experience:) thanks:)

Offline

#2 2006-12-08 19:11:42

hcgtv
Plugin Author
From: Miami, Florida
Registered: 2005-11-29
Posts: 2,721
Website

Re: Google Adsense inside an article?

Adam,

You can’t have more than 3 Google Ads per page.

  • Up to three ad units may be displayed on each Web site page.
  • A maximum of two Google AdSense for search boxes may be placed on a page.
  • A single link unit may be placed on each Web site page, in addition to the ad units and search boxes specified above. Link units are considered to be ‘Google ads’ for purposes of these program policies.
  • A single referral button per product may be placed on a page up to a maximum of 4 buttons, in addition to the ad units, search boxes, and link units specified above. Referral buttons are considered to be ‘Google ads’ for purposes of these program policies.
  • No Google ad may be placed on any non-content-based pages.
  • No Google ad or Google search box may be displayed on any domain parking websites, pop-ups, pop-unders, or in any email.
  • No Google ad may be placed on pages published specifically for the purpose of showing ads, whether or not the page content is relevant.
  • Elements on a page must not obscure any portion of the ads, and the ad colors must be such that any ad elements, including text and URL, are visible.
  • Clicks on Google ads must not result in a new browser window being launched.

Offline

#3 2006-12-08 20:01:03

adamtal
Member
Registered: 2006-09-14
Posts: 25

Re: Google Adsense inside an article?

Thanks mate. i am aware of the TOS… although i did not think of that.
I’m using one article on a page, though, so i guess it shouldn’t be a problem –

I just want to show the code once, after X words (or characters or lines, etc.) from the begining of the article. not to repeat after x words.

Offline

#4 2006-12-08 20:13:31

hcgtv
Plugin Author
From: Miami, Florida
Registered: 2005-11-29
Posts: 2,721
Website

Re: Google Adsense inside an article?

Just include it in your article, wherever you want it to appear.

I create forms for my ads, so let’s say after the second paragraph you would do:

<txp:output_form form="ads_728x90" />

Offline

#5 2006-12-09 08:24:59

adamtal
Member
Registered: 2006-09-14
Posts: 25

Re: Google Adsense inside an article?

Thanks.

The thing is i have other people adding content to my site, and i want an automatic process, so they won’t have to deal with ads or txp stuff.

I could use the ads on the sidebar, but i think it would really be better (visually, and practically) if i insert them between paragraphs – worked well for my non-txp sites.

Offline

#6 2006-12-09 14:17:16

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Google Adsense inside an article?

What about….making people write a leader (excerpt) then tell them that they don’t just paste that leader again into the main body, but they pick up where the leader left off so that you could do something like this:

<txp:excerpt />
<txp:output_form form="ads_728x90" />
<txp:body />

Offline

#7 2006-12-09 16:02:56

adamtal
Member
Registered: 2006-09-14
Posts: 25

Re: Google Adsense inside an article?

I think it would be easier to just tell them to put the AdSense thingy)

I was hoping there is a built in way to control the article tag or a plug-in, but after going over the resources and textbook, i guess there isn’t, so i guess i’ll have to wait for future versions or a plugin (or learn PHP:))

Thanks for the creativity, guys, i appreciate your time and effort.:)

Offline

#8 2006-12-09 17:41:47

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Google Adsense inside an article?

pageby should do it.

Offline

#9 2006-12-09 18:09:19

adamtal
Member
Registered: 2006-09-14
Posts: 25

Re: Google Adsense inside an article?

jm wrote:

pageby should do it.

I’ll appreciate it if you show me how. i only managed to use it to put ads between articles. I’m tryin to put them inside an article, only showing 1 article in a page.

Offline

#10 2011-10-22 14:07:24

whocarez
Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 278
Website GitHub Twitter

Re: Google Adsense inside an article?

Maybe it is for someone still interesting.
A php solution could look like that. I appreciate any improvements :-) ….

<txp:php>
$text=body();
$quantity=substr_count($text,'</p>');
if ($quantity>=5)
{
variable(array("name"=>"splitted", "value"=>"yes"));
$parts=explode('</p>',$text);

$i=0;
while ($i<2) {
echo $parts[$i].'</p>';
 $i++;
}

echo output_form(array('form'=>'related_articles_text'));
echo output_form(array('form'=>'google_ads_text'));
$i=2;
while ($i<count($parts)-1) {
echo $parts[$i].'</p>';
 $i++;
}

}

else 

{
echo($text);
}

</txp:php>

If you have more than 5 paragraphs in article body, than will be two forms put out after the second paragraph. In this case is the variable "splitted" also set to "yes".

Offline

#11 2018-03-02 23:18:39

singaz
Member
Registered: 2017-03-12
Posts: 147

Re: Google Adsense inside an article?

Modification.

If there are 5 paragraphs, then one form after the second paragraph. If there are more than 10 paragraphs, then one form after the second paragraph, the second form after the sixth paragraph.

<txp:php>
$text=body();
$quantity=substr_count($text,'</p>');
if ($quantity>=5)
{
variable(array("name"=>"splitted", "value"=>"yes"));
$parts=explode('</p>',$text);
$i=0;
while ($i<2) {
echo $parts[$i].'</p>';
 $i++;
}
echo output_form(array('form'=>'google_ads_1-one'));
if ($quantity>=10)
{	
$i=2;
while ($i<6) {
echo $parts[$i].'</p>';
 $i++;
}
echo output_form(array('form'=>'google_ads_2-two'));
$i=6;
while ($i<count($parts)-1) {
echo $parts[$i].'</p>';
 $i++;
}
}
else	
$i=2;
while ($i<count($parts)-1) {
echo $parts[$i].'</p>';
 $i++;
}
}
else 
{
echo($text);
}
</txp:php>

Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#12 2018-03-03 11:39:29

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: Google Adsense inside an article?

If you make sure that google_ads_1-one and google_ads_2-two forms output a valid XML, this can be shorten to

<txp:etc_query data='<txp:body />' separator="|\/|"
    replace='p[2]$=<txp:output_form form="google_ads_1-one" />|\/|
        p[6]$=<txp:output_form form="google_ads_2-two" />' />

Offline

Board footer

Powered by FluxBB