Adsense after the first entry

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Adsense after the first entry

Post 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!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adsense after the first entry

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Post 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>
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Post by Fila »

sorry about the color=red there..i thought i could make it red
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Post 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
Last edited by Fila on Sun Feb 24, 2008 6:26 am, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Post by Fila »

thanks garvin..

It works like charm!!!!!!!!!!!!!!!!!!!!!!

Fila
Fila
Regular
Posts: 34
Joined: Thu Oct 26, 2006 11:16 am

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post 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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

hmmm, forgot about that, Fila, scratch my suggestion, Garvin's is probably better and more usable.
Post Reply