Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
To divide body for adsense code
Dear friends,
Is there any way to divide txp article body by words or characters to insert adsense code inside the main text dynamically?
There is a way to do that through rss_auto_excerpt by patagraphs:
<txp:rss_auto_excerpt paragraphs="2" showlinkwithexcerpt="0" />
<txp:php>
$body_array = explode('</p>', $thisarticle['body']);
for($i=2;$i <= count($body_array);$i++){
echo $body_array[$i];
}
</txp:php>
from http://adminway.ru/dinamicheskoe-razmeshchenie-koda-kontekstnoi-reklamy-na-textpattern.
In my case I am trying divide article body whose content is a <table></table> which is one paragraph. How to divide it by words or characters if it is possible at all?
Offline
Re: To divide body for adsense code
The code you cite will produce unclosed <p>
tags (html5 valid, but not so clean). To insert some content after (say) the 2nd and the 5th rows of a table, you can use etc_query
, replacing <txp:body />
tag with
<txp:etc_query data='<txp:body />'
replace="//tr[2]|//tr[5]$=<tr>adsense code</tr>" />
Offline
Re: To divide body for adsense code
etc wrote #277742:
The code you cite will produce unclosed
<p>
tags (html5 valid, but not so clean). To insert some content after (say) the 2nd and the 5th rows of a table, you can useetc_query
, replacing<txp:body />
tag with
<code><txp:etc_query data='<txp:body />' replace="//tr[2]|//tr[5]$=<tr>adsense code</tr>" />
Thanx. So far it does not work. The code shows up just above the content. Interestingly it creates TRs 3d ans 6th but they are empty. May be something wrong with xPath syntaxis?
Last edited by admi (2014-01-07 18:24:53)
Offline
Re: To divide body for adsense code
What is the code you are trying to insert?
Edit: ah, ok, it misses <td>
s, sorry, it should be something like <tr><td colspan='3'>adsense code</td></tr>
. Also, if the adsense code contains ;
, you must set separator="something_other_than_;"
attribute of etc_query
.
Last edited by etc (2014-01-07 15:40:59)
Offline
Re: To divide body for adsense code
etc wrote #277858:
What is the code you are trying to insert?
Edit: ah, ok, it misses
<td>
s, sorry, it should be something like<tr><td colspan='3'>adsense code</td></tr>
. Also, if the adsense code contains;
, you must setseparator="something_other_than_;"
attribute ofetc_query
.
I think the problem may be with quote "..."
like src="adsense.google.com/lalalala"
in the adsense code as well. And may be some of js tags.
Last edited by admi (2014-01-07 19:46:21)
Offline
Offline
Re: To divide body for adsense code
etc wrote #277887:
Yes, as usual.
Well, i removed quotes from the code. It works without etc_query ok. Now I think the problem already in general in the tags <></>
. Is there any way to handle js here?
Offline
Re: To divide body for adsense code
Could you show me the adsense code, for testing? I have no problem inserting <script>
.
Offline
Re: To divide body for adsense code
etc wrote #277891:
Could you show me the adsense code, for testing? I have no problem inserting
<script>
.
Something like this:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-5859340735332440"
data-ad-slot="7118039316"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Offline
Re: To divide body for adsense code
You should assign a value to async
attribute, try
<txp:etc_query data='<txp:body />' separator=";;"
replace='//tr[2]$=<tr><td>
<script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-5859340735332440"
data-ad-slot="7118039316"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</td></tr>' />
Last edited by etc (2014-01-08 14:50:28)
Offline
Re: To divide body for adsense code
etc wrote #277894:
You should assign a value to
async
attribute, try
<code><txp:etc_query data='<txp:body />' separator=";;"...
Спасибо Олег! Thanx Oleg! TxP plugins are great but sometimes it takes lots of wits to grasp how they work!
Offline
Re: To divide body for adsense code
admi wrote #277937:
Спасибо Олег! Thanx Oleg! TxP plugins are great but sometimes it takes lots of wits to grasp how they work!
You are welcome, надеюсь, всё работает? I agree etc_query
is not the easiest to grok, but the problem in this case comes from XML specifications rather than from the plugin itself.
Offline
Pages: 1