Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-04-06 12:13:42

M_i
Member
Registered: 2006-03-05
Posts: 122

Looking for a conditional tag based on posting date.

Hello all,

I’m looking for a conditional tag (or something that’ll produce the same result) that works on posting date.

Basically, what I want to do is give recent articles (in lists that are sorted not by date but by title) a little icon that marks them as ‘<font color=“maroon”>NEW!</font>’ – so some sort of conditional tag (if posting date = less than a week ago, then image) would be ideal.

Looking forward to your suggestions!

-Iris

Offline

#2 2006-04-06 19:09:13

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Looking for a conditional tag based on posting date.

As a combined effort of this and that post, this is feasible by some inline PHP.

This snippet in an article form will add a proper class name in case the posting date is less than seven days past:

<p
<txp:php>
global $thisarticle;
$posted = $thisarticle['posted'];    # read posting date.
$new = ( time()- $posted ) < (7 * 24 * 60 * 60) ? ' class="new-icon"' : '';  # less than 7 days past
echo $new.'>' ;     # insert 'new' class name
</txp:php>
<txp:title /></p>

Which leaves us with a HTML snippet like that for articles within the last seven days:

<p class="new-icon">Post title goes here</p>

…while older posts are rendered that way:

<p>Post title goes here</p>

Then make it up with a little background styling:

p.new-icon { background: url(new.gif) no-repeat left top; padding-left: 20px; }

Works at my test site, give it a try!

Offline

#3 2006-04-06 19:12:48

M_i
Member
Registered: 2006-03-05
Posts: 122

Re: Looking for a conditional tag based on posting date.

Wow- that’s wonderful! Thank you so much!

Yours,
- Iris

Offline

Board footer

Powered by FluxBB