Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#71 2020-02-26 19:02:06

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,313
Website

Re: Textpattern evaluation (dis)abilities

Thanks everyone. This does work.

<txp:variable name="active_time">
    <txp:evaluate query='(<txp:yield name='days' /> * 86400) + (<txp:yield name='hours' /> * 3600) + (<txp:yield name='minutes' /> * 60)' />
</txp:variable>

I was trying to figure out a way to duplicate the functionality of csb_if_newer_than

function csb_if_newer_than($atts, $thing) {
	global $thisarticle;

	extract(lAtts(array(
			'days'  => '0',
			'hours'  => '0',
			'minutes'  => '0'
		),$atts));

	$active_time = $days * 86400 + $hours * 3600 + $minutes * 60;

	return (time() - $thisarticle['posted'] < $active_time) ? parse(EvalElse($thing, true)) : parse(EvalElse($thing, false));
}

but I am not sure it can be done.

Offline

#72 2020-02-27 02:17:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: Textpattern evaluation (dis)abilities

michaelkpate wrote #321941:

I was trying to figure out a way to duplicate the functionality of csb_if_newer_than

You can cheat with a partial solution. Create a shortcode Form called something like is_newer as follows:

<txp:php>
    global $thisarticle;

    $days = parse('<txp:yield name="days" default="0" />');
    $hours = parse('<txp:yield name="hours" default="0" />');
    $mins = parse('<txp:yield name="minutes" default="0" />');

    $active_time = $days * 86400 + $hours * 3600 + $mins * 60;

    echo parse('<txp:yield />', time() - $thisarticle['posted'] < $active_time);
</txp:php>

That could then be called like this:

<txp::is_newer hours="4" minutes="30">
   Article is newer than 4.5 hours!
</txp::is_newer>

The downside? I have no idea how to make it respond to <txp:else /> so it can process both true and false parts. All my tests failed so far. There’s probably a trick to it, but in the meantime this might get you moving in a good direction.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#73 2020-03-30 11:40:32

singaz
Member
From: Kyiv, Ukraine
Registered: 2017-03-12
Posts: 140

Re: Textpattern evaluation (dis)abilities

I need to do a check:
if there is an article with the status “sticky” and with the keywords=<txp:section />, then we display
<txp:article status="sticky" form="page-sections-sticky" keywords='<txp:section />' wraptag="div" class="section_sticky"/>
otherwise display
<h1 class="section-title"><txp:section title="1" /></h1>

Doing so:

<txp:evaluate query='<txp:article keywords /> = <txp:section />' >
	<txp:article status="sticky" form="page-sections-sticky" keywords='<txp:section />' wraptag="div" class="section_sticky"/>
		<txp:else />
	<h1 class="section-title"><txp:section title="1" /></h1>	
</txp:evaluate>

How to make a keyword comparison request?


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#74 2020-03-30 12:50:40

etc
Developer
Registered: 2010-11-11
Posts: 3,772
Website

Re: Textpattern evaluation (dis)abilities

You could try with <txp:article_custom /> itself:

<txp:article_custom status="sticky" keywords='<txp:section />' wraptag="div" class="section_sticky"/>
	<txp:output_form form="page-sections-sticky" />
<txp:else />
	<h1 class="section-title"><txp:section title="1" /></h1>
</txp:article_custom>

Offline

#75 2020-03-30 13:44:10

singaz
Member
From: Kyiv, Ukraine
Registered: 2017-03-12
Posts: 140

Re: Textpattern evaluation (dis)abilities

Everything turned out to be simple.

Thank you!


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

Board footer

Powered by FluxBB