Page 1 of 1

[solved] Counter for entries in entries.tpl needed?

Posted: Fri Dec 14, 2007 2:39 pm
by johncanary
Hello!

I just thought about being able to have a text, a banner, etc. appear only 1 time (or 3
times, or 4 times as configured) on a page.

For example:

You'll have AdSense on your overview pages, where you show 10 entries. You want
to a horizontal AdSense Block under each entry's summary. But you must not
show more than 3 of those blocks on a page.


One can test a numerical variable in the Smarty template that counts the
number of entries on the current page. Then include or not include the text.

But how and where would I set up this variable?
Is there such a variable already?

Yours
John

Re: Counter for entries in entries.tpl needed?

Posted: Fri Dec 14, 2007 2:45 pm
by garvinhicking
Hi!

Check the smarty {counter} function in the smarty function docs?

HTH,
Garvin

Posted: Fri Dec 14, 2007 4:26 pm
by Don Chambers
John - check out Carl's Affiliate template - I think he is doing something like that.... perhaps not exactly what you are requested, but his code might reveal a method you can adapt.

http://www.carlgalloway.com/pages/seren ... lates.html

Posted: Sat Dec 15, 2007 1:11 am
by johncanary
Thanks for your prompt replies. Sounds promising.
I'll check it out and will give you feedback.

Thanks

Posted: Fri Jan 18, 2008 12:56 am
by johncanary
Thanks for the tips. I am confident that I can figure it out based on that info.
It's just not of any high priority right now.
John

Solution

Posted: Thu Jun 12, 2008 6:58 pm
by johncanary
I finally found dealt with this one. Thanks to your tips, it was quite easy.
I used the Smarty Custom Function {counter}

For those, who want to hardcode their templates, too:

Code: Select all

# entries.tpl
##############
    ...
    {foreach from=$entries item="dategroup"}
    <div class="serendipity_Entry_Date">

        {foreach from=$dategroup.entries item="entry"}
        {counter name="entry_number" print=0 assign=entry_number}
        {if $entry_number == 2}
            {* AD HTML Code Start: shown at top of the second entry! *}
            <div>
                <a href="http://aff.example.com/?id=23">
                    <img src="http://aff.example.com/i/b45.jpg" alt=""
                        width="468" height="60" />
                </a>
            </div>
            {* AD HTML Code End *}
        {/if}
        <h4 class="serendipity_title"><a href="{$entry.link}">{$entry.title}</a></h4>
        <h3 class="serendipity_date">
        ...
This code will show the add on all multientry pages (like the home page, categories, ...) on top of the 2nd entry.