Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-02-23 06:39:48

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

[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

#2 2023-02-23 08:35:52

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

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

#3 2023-02-23 09:55:54

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

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

#4 2023-02-23 10:26:58

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

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

#5 2023-02-23 15:45:58

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

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

#6 2023-03-08 05:45:54

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

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

#7 2023-03-08 14:38:03

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: [Solved] Ugly code: how to improve it?

Pat64 wrote #334962:

Maybe the posted tag needs a time 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

#8 2023-04-03 02:16:43

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

Re: [Solved] Ugly code: how to improve it?

etc wrote #334970:

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 -->

Perfect!


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#9 2023-04-03 18:06:29

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: [Solved] Ugly code: how to improve it?

I would like to know more about <txp:posted time="next Friday" /> as it appears counter intuitive to me.

Does it actually mean that you post an article on a future date which happens to be the same as next Friday’s and will appear from today to next Friday? Also what happens to the visibility of the article on Saturday?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2023-04-04 01:32:53

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

Re: [Solved] Ugly code: how to improve it?

… Based on my tests on TXP 4.9-Dev, the time attribute allows us to display (not affect) a custom date of an article. Useful for some dates comparisons (e. with the evaluate tag).

Last edited by Pat64 (2023-04-04 01:36:29)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#11 2023-04-04 17:33:31

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: [Solved] Ugly code: how to improve it?

Well, txp somewhat lacks date tags (how do you output the current date?), so I have abused the internal time parameter of <txp:posted />, turning it into attribute. But this does not feel very clean, so a new <txp:date /> tag would be better, perhaps?

Offline

#12 2023-04-05 03:08:29

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,599
GitHub Twitter

Re: [Solved] Ugly code: how to improve it?

Sure! If you think it’s essential, a <txp:date /> tag could be extremely useful. Sometime, dealing with dates is currently difficult.


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB