Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2019-04-21 04:52:35
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 278
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
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
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.
Offline
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: 278
Re: How to offset or exclude from different categories ?
Thank you !
Solved the problem :-)
Offline
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