Page 1 of 1

Differentiating "today" in the posts list

Posted: Thu Mar 08, 2007 9:00 pm
by fdeckert
Hi dev,

The compagny I'm working for is using serendipity as the internal IT news system.

But we keep posting news about forthcoming events (like servers or network maintenance), and we were in need of differentiating "today" in the list of news so the users know "THIS is happening today", and "everything above will happen later".

So we added an attribute to the post during processing to base the style on in the template.

'Hope this will be of interest for you :-)

Florian

--- F:/serendipity/include/functions_entries.inc.php (revision 1639)
+++ F:/serendipity/include/functions_entries.inc.php (working copy)
@@ -924,6 +924,13 @@
}

$dategroup[$key]['date'] = $entries[$x]['timestamp'];
+//<FD
+ // mark the entry if it apply to today
+ $today =date(DATE_FORMAT_2);
+ $dt = date(DATE_FORMAT_2, $entries[$x]['timestamp']);
+ if ($dt == $today)
+ $dategroup[$key]['today']="yes";
+//FD>
$dategroup[$key]['is_sticky'] = (isset($entries[$x]['is_sticky']) && serendipity_db_bool($entries[$x]['is_sticky']) ? true : false);
$dategroup[$key]['entries'][] = &$entries[$x];
}

===================================================================
--- F:/serendipity/templates/carl_contest/entries.tpl (revision 1639)
+++ F:/serendipity/templates/carl_contest/entries.tpl (working copy)
@@ -3,12 +3,21 @@
{foreach from=$entries item="dategroup"}
{foreach from=$dategroup.entries item="entry"}
<div class="serendipity_Entry_Date">
+ {if $dategroup.today}
{if $dategroup.is_sticky}
+ <h3 class="serendipity_date_today">{$CONST.STICKY_POSTINGS}</h3>
+ {else}
+ <h3 class="serendipity_date_today">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
+ {/if}
+ </div>
+ {else}
+ {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}
</div>
+ {/if}
<div class="serendipity_entry serendipity_entry_author_{$entry.author|@makeFilename} {if $entry.is_entry_owner}serendipity_entry_author_self{/if} ">

<div class='serendipity_entryFooter'>

===================================================================
--- F:/serendipity/templates/carl_contest/style.css (revision 1639)
+++ F:/serendipity/templates/carl_contest/style.css (working copy)
@@ -213,6 +213,10 @@
border-bottom: 1px solid #ddd;
padding: 10px 12px 0 0; }

+.serendipity_date_today {
+ background:yellow;
+ }
+
/* entry title */
.serendipity_title {
font-size: medium;

Re: Differentiating "today" in the posts list

Posted: Fri Mar 09, 2007 10:31 am
by garvinhicking
Hi!

You can do that with smarty already, without needing to patch serendipity:

Code: Select all

     {foreach from=$entries item="dategroup"}
 	{foreach from=$dategroup.entries item="entry"}
     <div class="serendipity_Entry_Date">
        {if $dategroup.is_sticky}
         <h3 class="serendipity_date">{$CONST.STICKY_POSTINGS}</h3>
         {elseif $dategroup.date|@date_format:'%Y%m%d' == $smarty.now|@date_format:'%Y%m%d'}
          <h3 class="serendipity_date_today">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
         {else}
         <h3 class="serendipity_date">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
         {/if}
         </div>
[code]

Thanks for posting this to general use, though! I bet some people might be interested in this!

HTH,
Garvin

Posted: Fri Mar 09, 2007 8:38 pm
by fdeckert
Hi Gavin

I'm very much ashamed :oops: , It seems I know more about php than about smarty. Next time I'll read the manual twice before patching.

Thanks for your answer, I'm currently "un"patching my php code and pushing your recommendation in the smarty template.

I'm currently doing a couple of other patches to the code, so I'll check it can't be done otherwise :wink:

Posted: Sun Mar 11, 2007 12:56 pm
by garvinhicking
Hi!

No need to feel ashamed! You already found a working solution for you, so that's usually all that matters. I just wanted to tell you about an alternative that might be better to maintain - that's what we're here for. :-)

Best regards,
Garvin