Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-03-13 08:11:29

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

troubles with txp:related_articles

I’ve determined that txp:related_articles works if I don’t specify a match attribute and it works if I specify the match attribute as match="category1, category2" (which is the default). However if I specify any other attributes in match then the whole thing outputs blank.

Tagtrace provided these results:

     65.95 |    26.10 | 	<txp:related_articles match="cite_author, cite_title, keywords, category1, category2" limit="3">
     66.38 |    25.53 | 		[SQL: SELECT *, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod FROM textpattern WHERE 1 = 1 AND Status >= 4 AND Posted <= from_unixtime(2147483647) AND (from_unixtime(2147483647) <= Expires OR Expires IS NULL) AND ID NOT IN (2420) AND (Category1 IN ('mainstream') OR Category2 IN ('mainstream')) AND (FIND_IN_SET('party', Keywords) or FIND_IN_SET('sandbox', Keywords) or FIND_IN_SET('excerpt', Keywords)) and custom_1 like 'custom author name' and custom_2 like 'custom title here'  ORDER BY Posted DESC LIMIT 0, 3 ]
     91.92 |          | 		[Rows: 0]
     92.05 |          | 	</txp:related_articles>
     92.07 |    11.84 | 	<txp:related_articles limit="3">
     92.53 |    10.86 | 		[SQL: SELECT *, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod FROM textpattern WHERE 1 = 1 AND Status >= 4 AND Posted <= from_unixtime(2147483647) AND (from_unixtime(2147483647) <= Expires OR Expires IS NULL) AND ID NOT IN (2420) AND (Category1 IN ('mainstream') OR Category2 IN ('mainstream')) ORDER BY Posted DESC LIMIT 0, 3 ]
    103.41 |          | 		[Rows: 3]
    103.45 |          | 		[Article: '2419']
    103.52 |     0.07 | 		<txp:title />
    103.62 |          | 		[Article: '2380']
    103.66 |     0.03 | 		<txp:title />
    103.71 |          | 		[Article: '2255']
    103.75 |     0.03 | 		<txp:title />
    103.91 |          | 	</txp:related_articles>
    103.92 |     9.40 | 	<txp:related_articles match="category1, category2" limit="3">
    104.30 |     8.49 | 		[SQL: SELECT *, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod FROM textpattern WHERE 1 = 1 AND Status >= 4 AND Posted <= from_unixtime(2147483647) AND (from_unixtime(2147483647) <= Expires OR Expires IS NULL) AND ID NOT IN (2420) AND (Category1 IN ('mainstream') OR Category2 IN ('mainstream')) ORDER BY Posted DESC LIMIT 0, 3 ]
    112.80 |          | 		[Rows: 3]
    112.87 |          | 		[Article: '2419']
    112.94 |     0.06 | 		<txp:title />
    113.03 |          | 		[Article: '2380']
    113.07 |     0.03 | 		<txp:title />
    113.12 |          | 		[Article: '2255']
    113.16 |     0.03 | 		<txp:title />
    113.32 |          | 	</txp:related_articles>

textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#2 2017-03-13 08:56:01

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

Re: troubles with txp:related_articles

Are you sure to have any other article that has the same category, cite_author, cite_title and keywords that the current one?

Offline

#3 2017-03-13 09:13:35

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: troubles with txp:related_articles

Yes, I checked that. Even if those were blank though, I have category1 (and category2) also listed in match= so those should kick in, yes?

(I did test turning off all plugins; no difference.)

Last edited by alicson (2017-03-13 09:14:11)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#4 2017-03-13 10:08:26

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

Re: troubles with txp:related_articles

alicson wrote #304655:

Even if those were blank though, I have category1 (and category2) also listed in match= so those should kick in, yes?

No, all listed fields must match. Actually, it’s equivalent to calling <txp:article_custom /> with these attributes filled from the current article. Mind posting a link to the problematic page?

Offline

#5 2017-03-13 12:26:07

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: troubles with txp:related_articles

All listed fields must match? Is that practical? Shouldn’t it search in order of entry and find best matches accordingly?
Well that would be the clear reason then; if all listed fields must match, I’m going to need to use another solution.

Link to the page where I ran the tag trace (and thanks!)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#6 2017-03-13 17:24:10

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

Re: troubles with txp:related_articles

alicson wrote #304676:

All listed fields must match? Is that practical? Shouldn’t it search in order of entry and find best matches accordingly?

That’s debatable. I can see a use case for “same author AND same year”, but not for “same author OR same year”.

Offline

#7 2017-03-13 17:31:51

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

Re: troubles with txp:related_articles

i had a similar problem where events have more than one venue (CF name venue). THis worked with article custom

<txp:article_custom limit="999" label="Previously at NAC" venue="NeMe Arts Centre%" section="events,participations" labeltag="h3" break="li" wraptag="ul" class="submenu" />

Note the % mark at the end of the venue.


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

Offline

#8 2017-03-13 19:26:51

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: troubles with txp:related_articles

I was hoping it would find related articles based on 2 custom fields, keywords, and categories (in that order, if possible). If every one of those fields have to match, though, the list will very often be blank; no good. I could try using 3-4 instances of txp:related_articles to create one list, however that would be a very unruly list and just seems impractical.

The article_custom list seems good for full section/categories/fields, however am not sure I can use that for listing posts potentially similar/related to an individual article. Didn’t know we could use % though, that could be very helpful in general; is that true in all tags/custom field values?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#9 2017-03-13 19:53:14

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: troubles with txp:related_articles

alicson wrote #304699:

Didn’t know we could use % though, that could be very helpful in general; is that true in all tags/custom field values?

It’s a MySQL wildcard, so it only has this effect for attributes that go straight to the query. Not many do; offhand I don’t know how many.

Edit: Well, that’s not quite right: only for attributes where the query is a LIKE rather than = comparison. Again, not so many, I think.

Last edited by jsoo (2017-03-13 19:58:29)


Code is topiary

Offline

#10 2017-03-14 10:38:06

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

Re: troubles with txp:related_articles

We could probably map match="(Category1 | Category2), (keywords | some_cf)" to (Category1 OR Category2) AND (keywords OR some_cf) in 4.7, if it helps.

Offline

#11 2017-03-16 03:37:00

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: troubles with txp:related_articles

etc wrote #304718:

We could probably map match="(Category1 | Category2), (keywords | some_cf)" to (Category1 OR Category2) AND (keywords OR some_cf) in 4.7, if it helps.

:) I think that would be really helpful —for the tag to find closest matches rather than require exact/all-fields matching.

If we’re matching exact fields (as the tag seems to currently do), we could probably output the same with an article_custom list with variables that match the current article, yes? So related_articles being more flexible and matching either/or seems more useful I think (at least in the cases that are occurring to me).


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#12 2018-08-02 11:18:16

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: troubles with txp:related_articles

I use this for similar articles:

<txp:related_articles limit="4" wraptag="ul" break="li" sort="rand()" section='<txp:section />' >
  <div class="related-image">
    <a href="<txp:permlink />" rel="bookmark" title="<txp:title />"><txp:article_image thumbnail="1" width="230" height="180" /></a>
       <div class="related-text">
           <a href="<txp:permlink />"><txp:title /></a>
       </div>
  </div>
  <div class="related-small">
      <a href="<txp:permlink />" class="related-headline"><txp:title /></a>
   </div>
</txp:related_articles>

Displays articles with sticky status.

How to exclude articles with the status of sticky?


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

Offline

Board footer

Powered by FluxBB