Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-01-30 10:24:37

SPKuja
Member
From: England
Registered: 2013-05-18
Posts: 55
Website

Link to next article based on custom field

Hey guys, I wonder if some one can help.

I am trying to link to the next article based on the custom field entry. I thought some thing like this would work:

<txp:link_to_next YouTubeSeries=“alienisolation” ><txp:next_title /></txp:link_to_next>

I’m using glz_custom_fields to have more customer fields and YouTubeSeries is the name of the field. I basically only want to show the next article that has the same YouTubeSeries entry.

Any help would be greatly appreciated!

Offline

#2 2015-02-02 11:24:36

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

Re: Link to next article based on custom field

There currently seems to be no <txp:tag /> way, though the core code looks as if it was planned. Plugins (smd/etc_query, etc_search, ...) could do it, but <txp:php> solution is rather short:

<txp:variable name="previd"><txp:php>
global $thisarticle;
$prevart = getNeighbour( 
	'from_unixtime('.doSlash($thisarticle['posted']).')',
	$thisarticle['section'],
	'<',
	array('sortby'=>'Posted', 'sortdir'=>'desc', 'youtubeseries'=>$thisarticle['youtubeseries']) + filterAtts(),
	'cooked');
echo empty($prevart['ID']) ? '' : $prevart['ID'];
</txp:php></txp:variable>

<txp:if_variable name="previd" value=""><txp:else />
	<txp:article_custom form="your_link_to_prev_form" id='<txp:variable name="previd" />' />
</txp:if_variable>

Replace '<' with '>' for the next link, if it works at all (not tested with glz_custom_fields).

Edit: lowercase cf name and if_variable test.

Last edited by etc (2015-02-06 21:32:32)

Offline

#3 2015-02-02 16:03:02

SPKuja
Member
From: England
Registered: 2013-05-18
Posts: 55
Website

Re: Link to next article based on custom field

Thank you for the reply. Unfortunately it does not work. Is there any way to achieve a similar function using keywords?

Thank you in advance, I really appreciate the help.

Offline

#4 2015-02-02 17:06:14

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

Re: Link to next article based on custom field

I’m not sure if this will work


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

Offline

#5 2015-02-02 19:27:26

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

Re: Link to next article based on custom field

SPKuja wrote #287983:

Thank you for the reply. Unfortunately it does not work. Is there any way to achieve a similar function using keywords?

Works for me if cf name is lowercase: youtubeseries. Will probably work with keywords too (untested).

Offline

#6 2015-02-06 19:23:43

SPKuja
Member
From: England
Registered: 2013-05-18
Posts: 55
Website

Re: Link to next article based on custom field

etc wrote #287987:

Works for me if cf name is lowercase: youtubeseries. Will probably work with keywords too (untested).

Okay, I altered it to use lower case letters but when it gets to the 1st article it then shows all of the most recently posted articles. Is there any way to hide it once it is at the first article?

Offline

#7 2015-02-06 20:37:48

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

Re: Link to next article based on custom field

SPKuja wrote #288076:

Okay, I altered it to use lower case letters but when it gets to the 1st article it then shows all of the most recently posted articles. Is there any way to hide it once it is at the first article?

Yes, sorry. Replace echo $prevart['ID']; with

echo empty($prevart['ID']) ? '' : $prevart['ID'];

and call

<txp:if_variable name="previd" value=""><txp:else />
	<txp:article_custom form="your_link_to_prev_form" id='<txp:variable name="previd" />' />
</txp:if_variable>

Last edited by etc (2015-02-06 21:32:47)

Offline

#8 2015-02-24 13:21:05

SPKuja
Member
From: England
Registered: 2013-05-18
Posts: 55
Website

Re: Link to next article based on custom field

Sorry for the late reply. I still cannot get this to work. Is there any other method that may work? I can always do it based on category but I cannot seem to find any way to do that either. It doesn’t have to be by custom field, I just need a method to show the next article in the series, not every single article.

Offline

#9 2015-02-24 13:34:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Link to next article based on custom field

SPKuja wrote #288547:

I can always do it based on category but I cannot seem to find any way to do that either.

Could smd_horizon help at all? That can navigate between categories.


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

#10 2015-02-24 14:57:58

SPKuja
Member
From: England
Registered: 2013-05-18
Posts: 55
Website

Re: Link to next article based on custom field

Perfect! It works exactly as I need it too! Great plugin, thanks!

Offline

Board footer

Powered by FluxBB