Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-04-21 04:52:35

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

How to offset or exclude from different categories ?

I’ve three categories (technology, economic, sport)
on the home page, each category has different limit of articles, like:
technology = 4
economic = 6
sport = 3
At the bottom of home page there is an area of More News, here I want to show articles of that three categories except those articles which shows on the top already.
for example:

<txp:article_custom exclude="except_those_which_shows_on_the_top_already" category="technology, economic, sport" ....>

Offline

#2 2019-04-21 08:33:55

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,503
Website

Re: How to offset or exclude from different categories ?

You should be able to do that by storing the already displayed article_id values in a variable and then use that for the exclude attribute. Something like this:

<!-- set the variable once to start with -->
<txp:variable name="featured_articles" value="" />
...
<!-- your technology articles -->
<txp:article_custom section="technology" limit="4" … >
    ...
    <txp:variable name="featured_articles"><txp:variable name="featured_articles" /><txp:article_id />,</txp:variable>
</txp:article_custom>
...
<!-- your economic(s) articles -->
<txp:article_custom section="economic" limit="6" … >
    ...
    <txp:variable name="featured_articles"><txp:variable name="featured_articles" /><txp:article_id />,</txp:variable>
</txp:article_custom>
...
<!-- your sport articles -->
<txp:article_custom section="sport" limit="3" … >
    ...
    <txp:variable name="featured_articles"><txp:variable name="featured_articles" /><txp:article_id />,</txp:variable>
</txp:article_custom>
...
<!-- your "further links" -->
<txp:article_custom exclude='<txp:variable name="featured_articles" />' category="technology,economic,sport" … >
    ...
</txp:article_custom>

In the above the article_id of the 3+6+4 articles shown on the home page is appended to the variable “featured_articles” along with a comma, so that you end up with a comma-separated list of article ids. There’ll be a trailing comma but I think the final article_custom will ignore it.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-04-21 08:45:46

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

Re: How to offset or exclude from different categories ?

jakob wrote #317715:

There’ll be a trailing comma but I think the final article_custom will ignore it.

You can avoid it by using

<txp:variable name="featured_articles" add='<txp:article_id />' separator="," />

instead of

<txp:variable name="featured_articles"><txp:variable name="featured_articles" /><txp:article_id />,</txp:variable>

There is also no need to initialize the variable.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#4 2019-04-21 09:21:01

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,503
Website

Re: How to offset or exclude from different categories ?

Even better! Then you end up with:

<!-- your technology articles -->
<txp:article_custom section="technology" limit="4" … >
    ...
    <txp:variable name="featured_articles" add='<txp:article_id />' separator="," />
</txp:article_custom>
...
<!-- your economic(s) articles -->
<txp:article_custom section="economic" limit="6" … >
    ...
    <txp:variable name="featured_articles" add='<txp:article_id />' separator="," />
</txp:article_custom>
...
<!-- your sport articles -->
<txp:article_custom section="sport" limit="3" … >
    ...
    <txp:variable name="featured_articles" add='<txp:article_id />' separator="," />
</txp:article_custom>
...
<!-- your "further links" -->
<txp:article_custom exclude='<txp:variable name="featured_articles" />' category="technology,economic,sport" … >
    ...
</txp:article_custom>

TXP Builders – finely-crafted code, design and txp

Offline

#5 2019-04-21 13:37:04

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

Re: How to offset or exclude from different categories ?

Thank you !
Solved the problem :-)

Offline

#6 2019-04-21 17:09:15

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 1,494
Website

Re: How to offset or exclude from different categories ?

jakob wrote #317717:

Even better! Then you end up with:

<!-- your technology articles -->...

cool. I can make use of this on my site


…. texted postive

Offline

Board footer

Powered by FluxBB