Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Restrict articles from one section on Front page
In a Textpattern front page i want articles coming from two sections: all articles from News Section and just some, not all, articles from Albo Section.
I am using something like this
<txp:article_custom section=“news,album” sort=“posted desc” limit=“6” form=“my_form” />
This will pull in all articles from both sections.
Is it possible to have only a restricted selection of articles (flagged in some way: custom_field, keywords or whatever) from Album Section, and all articles from News?
I feel txp:variable tag can help… Any suggestion?
Offline
#2 2013-10-24 20:18:24
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Restrict articles from one section on Front page
Without a plugin I think your options are limited.
If you wanted to show all articles from Album and News on the front page, all you’d have to do is set On front page (in the Sections tab) to ‘yes’ (and to ‘no’ for all other sections), and use <txp:article limit="6" form="my_form" />
.
If you want to display only some articles from section Album and News, you can use a custom field. Name it – for instance – ‘front_page’ and enter ‘yes’ for the articles you want to display. The tag you need then is:
<txp:article limit="6" form="my_form" front_page="yes" />
(See <txp:article />
tag attributes.)
The downside to this is that you’d also need to enter the value ‘yes’ for all your articles in section News. I’m not sure how <txp:variable />
could be useful here, for what you want to do a plugin might be the simplest solution (like smd_query or etc_query).
Offline
Re: Restrict articles from one section on Front page
You could use <txp:variable />
, but it would require three queries instead of one:
<txp:variable name="ids">
<txp:article_custom section="news" limit="6" break=","><txp:article_id /></txp:article_custom>
</txp:variable>
<txp:variable name="ids">
<txp:variable name="ids" />,<txp:article_custom section="album" front_page="yes" limit="6" break=","><txp:article_id /></txp:article_custom>
</txp:variable>
<txp:article_custom id='<txp:variable name="ids" />' sort="posted desc" limit="6" form="my_form" />
Offline
Re: Restrict articles from one section on Front page
What a timely solution, etc.
I was going to study a plugin like smd_query or your etc_query, as suggested by Els.
Then I tried your method.
At first, it didn’t work: the front-page attribute does not exist.
So I just replaced front_page=“yes” with keywords”yes”, then I entered yes in the keyword field of the articles from section Album that I wanted to display and it worked, thank you.
Just now, I am realizing that I could have simply used a custom field named ‘front-page’ and enter ‘yes’ and that your solution has no errors.
Both, keywords=“yes” or custom_field (named front_page)=“yes” give me what I want.
Thanks again to you (and Els) for the great support.
Offline
#5 2013-10-25 11:44:57
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Restrict articles from one section on Front page
etc wrote:
You could use
<txp:variable />
Wow, that’s clever, this never crossed my mind…
Offline
Re: Restrict articles from one section on Front page
Els wrote:
Wow, that’s clever
Theoretically; actually, it could double the query time on large db (the third article_custom
should be fast).
Offline
#7 2013-10-25 13:42:56
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Restrict articles from one section on Front page
etc wrote:
it could double the query time on large db
And do etc_ or smd_query need the same amount of queries and query time, or are the plugins faster?
Offline
Re: Restrict articles from one section on Front page
Els wrote:
And do etc_ or smd_query need the same amount of queries and query time, or are the plugins faster?
Their query time is of the same order that <txp:article_custom />
, but you need only one query to retrieve all ids:
<txp:etc_query name="ids"
data="SELECT ID FROM textpattern WHERE (Section='news' OR Section='album' AND custom_1='yes') AND Status='4' AND ... ORDER BY Posted DESC LIMIT 6" break="," />
<txp:article_custom id='<txp:variable name="ids" />' form="my_form" />
Edit: added parentheses.
Last edited by etc (2013-10-25 19:39:28)
Offline
#9 2013-10-25 18:48:54
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Restrict articles from one section on Front page
etc wrote:
Their query time is of the same order that
<txp:article_custom />
, but you need only one query to retrieve all ids:
So if I understand you right, it would be more efficient to use the plugin? Apologies for all those questions, I’m only hoping to learn something here ;) Thanks for your patience! Just one more question:
<txp:etc_query name="ids"
data="SELECT ID FROM textpattern WHERE Section='news' OR Section='album' AND custom_1='yes' AND Status='4' AND ... ORDER BY Posted DESC LIMIT 6" break="," />
<txp:article_custom id='<txp:variable name="ids" />' form="my_form" />
Doesn’t this do exactly the same as the article tag in my first reply? Meaning that all articles in section News would also need to have ‘yes’ in the custom field?
Offline
Re: Restrict articles from one section on Front page
Els wrote:
So if I understand you right, it would be more efficient to use the plugin? Apologies for all those questions, I’m only hoping to learn something here ;)
Please don’t apologize, Els, feeling clever never hurts a man :) Plugins would certainly be more effective here for 1000 articles or more, because sorting time grows quickly, so the less queries the better. Moreover, <txp:article_custom />
retrieves all article data (body, excerpt and so on), even if you need only IDs. People often try to avoid using plugins (that was my attitude a year ago too), but that’s not always justified.
Doesn’t this do exactly the same as the article tag in my first reply? Meaning that all articles in section News would also need to have ‘yes’ in the custom field?
Oups, I have forgotten parentheses around Section
part, but no, this is not the same, because AND
has higher priority than OR
, so it reads Section='news' OR (Section='album' AND custom_1='yes')
.
Offline
#11 2013-10-25 20:06:31
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Restrict articles from one section on Front page
etc wrote:
AND
has higher priority thanOR
, so it readsSection='news' OR (Section='album' AND custom_1='yes')
.
Ah, didn’t know that. Thank you, Oleg!
Offline