Page 1 of 2
Adsense after the first entry
Posted: Thu Oct 26, 2006 11:22 am
by Fila
Hello there,
I wanna show adsense only after the first entry. I reached the forum and found this thread
http://www.s9y.org/forums/viewtopic.php?t=7087
I followed that but still couldn't get it. It still show the ads after all the entries.
I put the following code after {$entry.add_footer}
Code: Select all
{foreach name="dategroup" from=$dategroup.entries item="entry"}
{if $smarty.foreach.dategroup.first}
++adsense code++
{/if}
{/foreach}
Is there something wrong with it?
Thanks a lot!
Re: Adsense after the first entry
Posted: Thu Oct 26, 2006 12:21 pm
by garvinhicking
Hi!
Do not put that foreach loop in there, but modify this loop you should find at the top of your entries.tpl file.
After add_footer, only place this:
Code: Select all
{if $smarty.foreach.dategroup.first}
++adsense code++
{/if}
HTH,
Garvin
Posted: Fri Oct 27, 2006 3:43 am
by Fila
Thanks garvin for help but i still caouldnt make it work
This is the code
Code: Select all
<!-- ENTRIES START -->
{serendipity_hookPlugin hook="entries_header" addData="$entry_id"}
{foreach from=$entries item="dategroup"}
<div class="serendipity_Entry_Date">
{if $dategroup.is_sticky}
<h3 class="serendipity_date">{$CONST.STICKY_POSTINGS}</h3>
{else}
<h3 class="serendipity_date">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
{/if}
{foreach name="dategroup" from=$dategroup.entries item="entry"}
<h4 class="serendipity_title"><a href="{$entry.link}">{$entry.title}</a></h4>
<div class="serendipity_entry serendipity_entry_author_{$entry.author|@makeFilename} {if $entry.is_entry_owner}serendipity_entry_author_self{/if}">
{if $entry.categories}
<span class="serendipity_entryIcon">
{foreach from=$entry.categories item="entry_category"}
{if $entry_category.category_icon}
<a href="{$entry_category.category_link}"><img class="serendipity_entryIcon" title="{$entry_category.category_name|@escape}{$entry_category.category_description|@emptyPrefix}" alt="{$entry_category.category_name|@escape}" src="{$entry_category.category_icon}" /></a>
{/if}
{/foreach}
</span>
{/if}
<div class="serendipity_entry_body">
{$entry.body}
</div>
{if $entry.is_extended}
<div class="serendipity_entry_extended"><a id="extended"></a>{$entry.extended}</div>
{/if}
{if $entry.has_extended and not $is_single_entry and not $entry.is_extended}
<br /><a href="{$entry.link}#extended">{$CONST.VIEW_EXTENDED_ENTRY|@sprintf:$entry.title}</a><br /><br />
{/if}
<div class='serendipity_entryFooter'>
{$CONST.POSTED_BY} <a href="{$entry.link_author}">{$entry.author}</a>
{if $entry.categories}
{$CONST.IN} {foreach from=$entry.categories item="entry_category" name="categories"}<a href="{$entry_category.category_link}">{$entry_category.category_name|@escape}</a>{if not $smarty.foreach.categories.last}, {/if}{/foreach}
{/if}
{if $dategroup.is_sticky}
{$CONST.ON}
{else}
{$CONST.AT}
{/if} <a href="{$entry.link}">{if $dategroup.is_sticky}{$entry.timestamp|@formatTime:DATE_FORMAT_ENTRY} {/if}{$entry.timestamp|@formatTime:'%H:%M'}</a>
{if $entry.has_comments}
{if $use_popups}
| <a href="{$entry.link_popup_comments}" onclick="window.open(this.href, 'comments', 'width=480,height=480,scrollbars=yes'); return false;">{$entry.label_comments} ({$entry.comments})</a>
{else}
| <a href="{$entry.link}#comments">{$entry.label_comments} ({$entry.comments})</a>
{/if}
{/if}
{if $entry.has_trackbacks}
{if $use_popups}
| <a href="{$entry.link_popup_trackbacks}" onclick="window.open(this.href, 'comments', 'width=480,height=480,scrollbars=yes'); return false;">{$entry.label_trackbacks} ({$entry.trackbacks})</a>
{else}
| <a href="{$entry.link}#trackbacks">{$entry.label_trackbacks} ({$entry.trackbacks})</a>
{/if}
{/if}
{if $entry.is_entry_owner and not $is_preview}
| <a href="{$entry.link_edit}">{$CONST.EDIT_ENTRY}</a>
{/if}
{$entry.add_footer}
[color=red]{if $smarty.foreach.dategroup.first}
++adsense code++
{/if} [/color]
</div>
</div>
Posted: Fri Oct 27, 2006 3:44 am
by Fila
sorry about the color=red there..i thought i could make it red
Posted: Fri Oct 27, 2006 9:19 am
by garvinhicking
Hi!
Hi!
Can you tell us your URL to look at it? Are you sure you are modifying the right entries.tpl file? The code looks proper to me...
Best regards,
Garvin
Posted: Fri Oct 27, 2006 10:12 am
by Fila
Hi garvin,
I edited it in templates/default/entries.tpl
Is that correct? it still shows under all entries
Thanks a lot!
Fila
Posted: Fri Oct 27, 2006 10:31 am
by garvinhicking
Hi!
I just tried the code you posted, and this works here for me. So my guess is that you are not editing the right file.
Try to replace "++adsense code++" with "!!adsense code!!" and see if that displays in your blog then?
Regards,
Garvin
Posted: Fri Oct 27, 2006 10:38 am
by Fila
garvinhicking wrote:Hi!
I just tried the code you posted, and this works here for me. So my guess is that you are not editing the right file.
Try to replace "++adsense code++" with "!!adsense code!!" and see if that displays in your blog then?
Regards,
Garvin
the place to edit entries.tpl is templates/defualt/entries.tpl right?
Adsense shows up but it shows under ALL entries I have just like you see it now with the word "ADSENSE CODE" under all the entries.
Thanks
Fila
Posted: Fri Oct 27, 2006 11:25 am
by garvinhicking
Hi!
Okay, try this.
Modify
Code: Select all
{foreach from=$entries item="dategroup"}
into
Code: Select all
{foreach name="outerdategroup" from=$entries item="dategroup"}
and
Code: Select all
{if $smarty.foreach.dategroup.first}
++adsense code++
{/if}
into:
Code: Select all
{if $smarty.foreach.dategroup.first AND $smarty.foreach.outerdategroup.first}
++adsense code++
{/if}
The file is then the right one, sorry for my misuse. I believe it will be printed if each of your entries is on a seperate day. I only tested for entries that were posted the same day.
HTH,
Garvin
Posted: Fri Oct 27, 2006 4:07 pm
by Fila
thanks garvin..
It works like charm!!!!!!!!!!!!!!!!!!!!!!
Fila
Posted: Wed Nov 08, 2006 11:46 am
by Fila
Sorry for the trouble again but what if I want it on the third entry too?
will it be
Code: Select all
{if $smarty.foreach.dategroup.third AND $smarty.foreach.outerdategroup.third}
++adsense code++
{/if}
??
Thanks
Fila
Posted: Wed Nov 08, 2006 12:15 pm
by garvinhicking
Hi!
This is much harder to solve, as there is no running index currently that you can check. "First" is a hardcoded value, third will not work because of nested loops.
You will need to assign a smarty {counter} value in the innermost loop and then check on that counter variable to see if it contains a "3". This is more advanced, so you will need to consult the Smarty documentation for more details. Or maybe some other helping soul here on the forums can lay it out for you.
Best regards,
Garvin
Posted: Wed Nov 08, 2006 5:29 pm
by carl_galloway
Fila did you get this working? I have a working sample that I used to use on my own blog that placed adsense after the first, third and fifth entry, but my entries.tpl was heavily customised for my purposes so posting it here for you to download wouldn't help you, let me know if you want yours changed to do this.
Posted: Wed Nov 08, 2006 7:48 pm
by garvinhicking
Hi!
Now that carl mentions it: Did you have a look at the serendipity 'serendipity_event_includeentry' plugin ("Include entry blocks" or something like that). This actually allows you to post/use specific "blocks" after X entries.
Best regards,
Garvin
Posted: Wed Nov 08, 2006 7:53 pm
by carl_galloway
hmmm, forgot about that, Fila, scratch my suggestion, Garvin's is probably better and more usable.