Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[Solved] Ugly code: how to improve it?
Here is my ugly code. Is there a better way?
<txp:article_custom section='<txp:section />' time="future" limit="1" sort="LastMod desc"><txp:php>
/*
* Compare a future last modified (5 days before) article to
* current date, display a message if the result is true
*/
$post = posted(array('format'=> '%s'));
echo( (strtotime(date('Y-m-d', strtotime('-5 days', $post))) <= safe_strftime("%s") ? '<p class="mt2em txt-c fs120% #a00" id="limited"> Hurry Up!</p>' : '') );</txp:php>
</txp:article_custom>
Last edited by Pat64 (2023-02-23 10:45:35)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Ugly code: how to improve it?
Try this:
<txp:if_expired date="modified" time="+5 days">
<p class="mt2em txt-c fs120% #a00" id="limited"> Hurry Up!</p>
</txp:if_expired>
Offline
Re: [Solved] Ugly code: how to improve it?
…That’s not an expired article, but posted into the future… To be displayed during 5 days before the published date…
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Ugly code: how to improve it?
… Sorry… That’s seems to work (I need to test more). But only in individual article context.
Okay. Here is the final code for both article list and individual context:
<txp:variable name="limited" trim output>
<txp:article_custom section="articles" limit="1">
<txp:if_expired date="modified" time="+5 days">
<p>Hurry !!</p>
</txp:if_expired>
</txp:article_custom>
</txp:variable>
Thanks lot Oleg ;)
It’s definitively obvious that only Devs are the best Textpattern users.
Last edited by Pat64 (2023-02-23 10:46:00)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Ugly code: how to improve it?
Pat64 wrote #334723:
…That’s not an expired article, but posted into the future…
This makes me think that time
should rather be relative to date
than to the current time. Would this look more natural for what you need?
<!-- subtract 5 days from LastMod and compare with the current time -->
<txp:if_expired date="modified" time="-5 days" />
Since you must be the only user of this 4.8.8-feature atm, we can yet change it if you agree.
Offline
Re: [Solved] Ugly code: how to improve it?
Maybe the posted
tag needs a time
attribute to allow such a filter…
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: [Solved] Ugly code: how to improve it?
Pat64 wrote #334962:
Maybe the
posted
tag needs atime
attribute to allow such a filter…
Not sure to understand. Per se, <txp:posted />
does not filter articles, it just outputs their timestamps.
BTW, <txp:posted />
has time
attribute in dev:
<txp:posted time="posted" /> <!-- default -->
<txp:posted time="modified" /> <!-- LastMod -->
<txp:posted time="next Friday" /> <!-- and so on -->
Offline