Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-10-18 23:59:30

pwg
Member
From: *sunny* Melbourne, Au
Registered: 2004-02-24
Posts: 14
Website

Conditionally display a single article based on time since posted

Many of the visitors to my site are, apparently, researchers — usually students — who are looking for materials that they can use in some assignment or other. I’d like to ask them to register to view articles older than e.g. 14 days.

On my site, viewing any result from a list of articles returned by a search, for example, or an archive listing or just linking from the ‘excerpt’ (on front page) to the body of the article ‘over the fold’ uses a form that displays a single article in a section entitled ‘article’.

I would like to include a conditional in that form that determines if the ‘posted’ date of the article being displayed is older than e.g. 14 days and, if so, calls mem_self-register to request registration — if the user is not already registered.

I suspect that testing the posted date is not difficult (although beyond me). I don’t want to DISPLAY the date, however, as in Filip Hajny’s very complete fha_time_diff. I want to use the date in the conditional statement.

I have searched here and on textpattern.net without success for an existing ‘plugin’ or method.

Can someone help me, please?


Peter Gallagher — www.petergallagher.com.au — inquit pty ltd

Offline

#2 2005-10-19 02:58:38

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Conditionally display a single article based on time since posted

This tag is a fairly quick (and untested as yet ) idea that I can make run from inside an article form. It tests for a set length of time, or greater, in the past against the posted time and returns true or false.
<pre>
function ras_if_expired($atts,$thing)
{ global $thisarticle; extract(lAtts(array( ‘offset’ => ‘14’, ),$atts)); $offset = $offset * 86400; $condition = (mktime() – $offset) <= $thisarticle[‘posted’] ? true : false; return parse(Evalelse($thing, $condition));
}
</pre>
Tags would look like this:

<code>
<txp:ras_if_expired>
statement if time has not expired
<txp:else />
statement if time has expired
</txp:ras_if_expired>
</code>

The ‘offset’ variable would allow you to vary the time constraint.
How to get folks to the self register option with this is something I’m not sure about, I don’t use self register. If you would be curious to try it, I’ll put it in a plugin and link it for you.

[edit] gotta go: Link : <a href=“http://textcastle.com/file_download/21” title=“if_expired.txt”>if_expired.txt</a> let me know how it works.

Last edited by rsilletti (2005-10-19 04:56:03)

Offline

#3 2005-10-19 03:15:41

pwg
Member
From: *sunny* Melbourne, Au
Registered: 2004-02-24
Posts: 14
Website

Re: Conditionally display a single article based on time since posted

Thanks very much Rick. I’ll test it in the next couple of hours and get back to you. Appreciate your help.

Peter


Peter Gallagher — www.petergallagher.com.au — inquit pty ltd

Offline

#4 2005-10-19 04:54:27

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Conditionally display a single article based on time since posted

A quick rework with a reversal of the testing, now that I look at it, the tag structure and name are intuitively incorrect.
This might be less confusing: <a href=“http://textcastle.com/file_download/23” title=“ras_if_expired.txt”>ras_if_expired.txt</a>

This will also allow you to drop the else clause if you don’t need it.

Tags:
<code><txp:ras_if_expired offset=“4”></code>
<code>statement if 4 days or more have passed since the posting date</code>
<code></txp:ras_if_expired></code>

Last edited by rsilletti (2005-10-19 05:56:28)

Offline

#5 2005-10-19 07:21:29

pwg
Member
From: *sunny* Melbourne, Au
Registered: 2004-02-24
Posts: 14
Website

Re: Conditionally display a single article based on time since posted

Hi Rick,

Works well, thank you. Thanks for reversing the logic/name and for making the offset ‘soft’: exactly the changes I would have asked for. Funny thing is, I can’t see any change in the code showing up in Textpattern … I guess there is a caching issue(?). But it works as advertised. That’s what matters.

I’ll now try to integrate registration for older stories.

Incidentally, my theory on this is that 14 days should be plenty of time for the search engine robots to index the article before it disappears behind a registration ‘barrier’ (a pretty transparent barrier, but not for the spiders).

Thanks again for your quick help.

Peter


Peter Gallagher — www.petergallagher.com.au — inquit pty ltd

Offline

#6 2005-10-20 00:10:52

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Conditionally display a single article based on time since posted

You`re welcome, let me know if there are any refinements that may make integrating into your site easier.

Offline

#7 2006-07-25 22:25:11

titilayo
New Member
Registered: 2006-07-25
Posts: 9

Re: Conditionally display a single article based on time since posted

I’ve tried downloading this plug-in and haven’t been able to. Anyone know if it’s still available, and if not, how I could get something similar?

Offline

Board footer

Powered by FluxBB