Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-12-31 05:31:35

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 278

How to exclude articles showing in home page ?

I’ve a news website, at the bottom of website I need two sections:

1. Articles custom list except a specific category
for example <txp:article_custom exclude_category="feature" limit="5" ...

2. Those articles which is not available at home page
for example <txp:article_custom exclude="all those showing at home page" ...

Offline

#2 2022-12-31 18:22:01

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

Re: How to exclude articles showing in home page ?

The first one looks easy:

<txp:article_custom exclude="category" category="feature" limit="5" ... />

As for the second one, I’m not sure what you mean by exclude="all those showing at home page". If it is ‘beyond the limit attribute (say, 5) of <txp:article ... limit="5" />’, use offset:

<txp:article_custom ...atts of home page... offset="5" />

Otherwise, please be more specific.

Offline

#3 2022-12-31 20:38:47

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

Re: How to exclude articles showing in home page ?

As etc says, the second case can be solved in a few ways depending on what you mean. Using offset is easy if the articles in the top of the home page are from a single section or simply the most recent articles from a bunch of sections.

If they’re curated in any other way, I would use a variable to stash the IDs of the ones being shown. This is untested, but something along these lines might work to make a concatenated, comma-separated list of articles in the top section:

<txp:variable name="already_seen" value="" />
<article::custom whatever_attributes_go_here>
    <txp:title wraptag="h2" />
    <txp:excerpt />
    <txp:variable name="already_seen" add='<article::id />' separator="," />
</article::custom>

… which can then be excluded later in the page:

<h1>Rest of the articles</h1>
<article::custom id='<txp:variable name="already_seen" />' exclude>
    ...
</article::custom>

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

#4 2023-01-01 06:19:00

raminrahimi
Member
From: India
Registered: 2013-03-19
Posts: 278

Re: How to exclude articles showing in home page ?

Here is the prototype → link

I’ve different categories and listing it’s own 5 recent articles in the home page like Sport, Technology, Politics, etc..
at the bottom of page home page, I want to show some more articles from all categories except those already appear at the top to prevent duplicate articles.

Offline

#5 2023-01-01 06:46:08

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

Re: How to exclude articles showing in home page ?

does this work for you?

<txp:variable name="vsport"><txp:article_custom category="sport" limit="4" wraptag="" break=","><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="vtechnology"><txp:article_custom category="technology" limit="4" wraptag="" break=","><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="veconomic"><txp:article_custom category="economic" limit="4" wraptag="" break=","><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="vpolitics"><txp:article_custom category="politics" limit="4" wraptag="" break=","><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="varts"><txp:article_custom category="arts" limit="4" wraptag="" break=","><txp:article_id /></txp:article_custom></txp:variable>
<txp:variable name="vhealth"><txp:article_custom category="health" limit="4" wraptag="" break=","><txp:article_id /></txp:article_custom></txp:variable>

<txp:article_custom category="sport" id='<txp:variable name="vsport" />' break="li" wraptag="ul" label="Sport" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

<txp:article_custom category="technology" id='<txp:variable name="vtechnology" />' break="li" wraptag="ul" label="Technology" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

<txp:article_custom category="economic" id='<txp:variable name="veconomic" />' break="li" wraptag="ul" label="Economic" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

<txp:article_custom category="politics" id='<txp:variable name="vpolitics" />' break="li" wraptag="ul" label="Politics" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

<txp:article_custom category="arts" id='<txp:variable name="varts" />' break="li" wraptag="ul" label="Arts" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

<txp:article_custom category="health" id='<txp:variable name="vhealth" />' break="li" wraptag="ul" label="Health" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>


<txp:variable name="more"><txp:article_custom limit="100" category="sport,technology,economic,politics,arts,health" exclude='<txp:variable name="vsport" />,<txp:variable name="vtechnology"/>,<txp:variable name="veconomic' />,<txp:variable name="vpolitics' />,<txp:variable name="varts" />,<txp:variable name="vhealth" />' break="," wraptag=""><txp:article_id /></txp:article_custom></txp:variable>

<txp:article_custom limit="4" id='<txp:variable name="more" />' wraptag="ul" break="li" label="More Articles" labeltag="h3">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>

>Edited some typos

Last edited by colak (2023-01-01 07:56:58)


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

Offline

#6 2023-01-01 10:55:52

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

Re: How to exclude articles showing in home page ?

Stef’s solution looks perfect. I would just explicitly set a value for exclude, otherwise other eventual attributes (like section, etc) will be excluded too:

<article::custom id='<txp:variable name="already_seen" />' exclude="id" />

or

<article::custom exclude='<txp:variable name="already_seen" />' />

Offline

Board footer

Powered by FluxBB