Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-02-19 16:08:45

ia278
Member
From: UK
Registered: 2018-11-07
Posts: 17
Website

Setting recommended related articles

Hi all – I’ve got a small problem!

My website has two main article sections (portfolio and journal). The plan is to set 4-5 articles from each section as “recommended”, and then have three of these appear in a tab at the bottom of the post, without duplicating articles (so if I’m viewing one of the recommended articles, the tab won’t display the article that’s being viewed).

But what I’m doing so far isn’t working! I’ve come at the problem from three different directions;

1. Using related articles

<txp:related_articles break="" class="landing-listing" form="article_listing_post" limit="3" match="Category1" section="portfolio" sort="rand()" wraptag="div" />

This method sets the category 1 of the articles I want to promote to “recommended” (while leaving this blank for all others). It displays the articles how I want, but only on recommended articles. For articles that aren’t recommended, no articles are shown at all.

2. Using article_custom

<txp:article_custom break="" class="landing-listing" form="article_listing_post" limit="3" exclude="<txp:article_id />" match="Category1" section="portfolio" sort="rand()" wraptag="div" />

This method also sets the category 1 of the articles I want to promote to “recommended” (while leaving this blank for all others). While this method shows a list for all articles, this list isn’t filtered in the way that I want – as it randomly selects three articles in the section. Adding to this, the current article isn’t always excluded from the recommended list.

3. Using smd_featured

This method would set the articles I wanted to recommend in the plugin’s special tab (and not by setting category). While the plugin seems to do most of what I want, it doesn’t have an attribute to exclude the present article (and I can’t figure out how it could be done). Because of this, the current article could be duplicated in the recommended tab.

So, I guess my question is – any ideas?

Offline

#2 2019-02-19 16:27:55

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Setting recommended related articles

Hi Isaac,

With 1) the match refers to the “matches which field of the current article” so that explains why it only works on articles where Category1 is assigned to the “recommended” category. I’m not sure (I use the tag so rarely), but it may work as you wish with the category="recommended" attribute instead of match.

With 2) try using category="recommended" instead of match and for the tag-in-tag exclude attribute you need single quotes to make it process the tag and place the result as the attribute, e.g.

<txp:article_custom form="article_listing_post" class="landing-listing"
                    limit="3" exclude='<txp:article_id />' sort="rand()"
                    category="recommended" section="portfolio"
                    break="" wraptag="div" />

TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-02-19 16:47:49

ia278
Member
From: UK
Registered: 2018-11-07
Posts: 17
Website

Re: Setting recommended related articles

That solved it, thanks Jakob!

Oh, and another thank you for the heads-up on the single quotes tag tip – a lot of conditional code has just been stripped from my pages :-)

Offline

#4 2019-02-19 17:51:53

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Setting recommended related articles

ia278 wrote #316657:

That solved it, thanks Jakob!

Glad that fixed it.

Oh, and another thank you for the heads-up on the single quotes tag tip – a lot of conditional code has just been stripped from my pages :-)

Yep, it’s truly very useful and also quite powerful. Over the past few version updates, the devs, and Oleg in particular, have been making attributes successively more powerful so that many plugins that were previously staples are needed less and less.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB