Page 1 of 1

Give the most recent entry its own class (CSS)

Posted: Wed Sep 16, 2009 3:04 pm
by aschlemmer
Hi all,

while trying to format the most recent entry on the start page with a special CSS attribute, eg. font-weight: bold;, I'm stumbling upon the question on how to identify this most recent entry?

Example:
.most_recent { font-size: 120%; font-weight: bold; }
Entry 1: Date
Text 1 Text1 Text 1 Text1 Text 1 Text1 Text 1 Text1


Entry 2: Date
Text2 Text2 Text2 Text2 Text2 Text2 Text2 Text2

Entry 3: Date
Text3 Text3 Text3 Text3 Text3 Text3 Text3 Text3

...


Maybe I should operate with "max(timestamp)" in an SQL query? How to do that, when not experienced with advanced PHP/SQL topics?

Thanks for a hint,
Achim

Re: Give the most recent entry its own class (CSS)

Posted: Wed Sep 16, 2009 5:11 pm
by garvinhicking
Hi!

Actually this is quite hard to achieve.

You can format the first article on any page via a small tweak in your entries.tpl, but it's not so easy to really fetch the most recent article timestamp, for that you'd need an event plugin.

Maybe displaying the first entry is easiest to achieve, then you only need to check your entries.tpl and use {if $smarty.foreach.(loopname).first}class="first"{/if} in the <div> construct; replace "loopname" for the {foreach item=$entries name="LOOPNAME"}.

HTH,
Garvin

Re: Give the most recent entry its own class (CSS)

Posted: Wed Sep 16, 2009 5:42 pm
by aschlemmer
Hi!

Thank you for the quick answer.

So it's all about smarty and the loop ... and no simple solution (for me).
Since we do only need the very first (the most recent) entry on the start page with a special CSS class, your {if $smarty.foreach.(loopname).first}class="first"{/if} could help, I think.
Unfortunately, my trials did always end up in Smarty errors (due to missing knowledge on my side).

I stop my trials for today, and read something about Smarty and its loops, maybe I have better luck on the next day ...

Thanks anyway,
Achim

Re: Give the most recent entry its own class (CSS)

Posted: Wed Sep 16, 2009 8:40 pm
by garvinhicking
Hi!

Something like:

Code: Select all

{foreach from=$entries item="dategroup" name="outerloop"}
   {foreach from=$dategroup.entries item="entry" name="innerloop"}
    
    {if $smarty.innerloop.first && $smarty.outerloop.first}
    <div class="first">
    {else}
    <div>
    {/if}

    ....

   {/foreach}
{/foreach}
Grüße,
Garvin

Re: Give the most recent entry its own class (CSS)

Posted: Thu Sep 17, 2009 12:42 am
by yellowled
There's always the option to use an individual start page instead, i.e. an index.tpl which doesn't pull the selected number of entries but uses serendipity_fetchPrintEntries command(s) to pull articles. The Mimbo template is an example for this technique.

YL

Re: Give the most recent entry its own class (CSS)

Posted: Thu Sep 17, 2009 11:18 am
by aschlemmer
Hello there,
thanks you so much for your answers -- I'm afraid that a s9y-creation is good for programmers and not so good for content developers with less coding skills :shock:

Looking in the mimbo templates code, I read so much smarty code that is more a problem than that it helps me -- just another signal for me to learn more about smarty.

As the required special treatment for the most recent post is only one feature of several that I have to create, so I'm now trying my luck in other construction areas -- those require the next forum question :D

But one day, I will come back to the recent post subject and I'm willing to solve it in the future. (= learn Smarty)

Regards,
Achim

Re: Give the most recent entry its own class (CSS)

Posted: Thu Sep 17, 2009 12:02 pm
by yellowled
aschlemmer wrote:I'm afraid that a s9y-creation is good for programmers and not so good for content developers with less coding skills :shock:
I am really not a programmer myself, but Smarty isn't that hard if you have some time to get into it. And it gives you great tools to accomplish almost anything.
aschlemmer wrote:Looking in the mimbo templates code, I read so much smarty code that is more a problem than that it helps me -- just another signal for me to learn more about smarty.
Yes, Mimbo is rather sophisticated templating :) It is most definitely not an ideal place to start getting into advanced templating, that would be the documentation on s9y.org and/or the Smarty docs.

YL

Re: Give the most recent entry its own class (CSS)

Posted: Fri Sep 25, 2009 10:57 pm
by abdussamad
garvinhicking wrote:Hi!

Something like:

Code: Select all

{foreach from=$entries item="dategroup" name="outerloop"}
   {foreach from=$dategroup.entries item="entry" name="innerloop"}
    
    {if $smarty.innerloop.first && $smarty.outerloop.first}
    <div class="first">
    {else}
    <div>
    {/if}

    ....

   {/foreach}
{/foreach}
Grüße,
Garvin
Combine the above with a check for the frontpage and you have what the OP asked for :

Code: Select all

{foreach from=$entries item="dategroup" name="outerloop"}
   {foreach from=$dategroup.entries item="entry" name="innerloop"}
    
    {if $startpage && $smarty.innerloop.first && $smarty.outerloop.first}
    <div class="first">
    {else}
    <div>
    {/if}

    ....

   {/foreach}
{/foreach}