Give the most recent entry its own class (CSS)

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
aschlemmer
Regular
Posts: 70
Joined: Fri Feb 23, 2007 6:13 pm
Location: Freiburg/Germany
Contact:

Give the most recent entry its own class (CSS)

Post 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
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post 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
# 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/
aschlemmer
Regular
Posts: 70
Joined: Fri Feb 23, 2007 6:13 pm
Location: Freiburg/Germany
Contact:

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

Post 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
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post 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
# 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/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

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

Post 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
aschlemmer
Regular
Posts: 70
Joined: Fri Feb 23, 2007 6:13 pm
Location: Freiburg/Germany
Contact:

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

Post 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
www.ms-reporter.de
Pharma-unabhängige Infos für Multiple Sklerose-Betroffene
schnellze.it
Einzigartiges Zusammenspiel aus Popfetcher und s9y
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

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

Post 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
abdussamad
Regular
Posts: 117
Joined: Fri Apr 21, 2006 10:11 pm
Location: Karachi, Pakistan
Contact:

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

Post 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}
Post Reply