Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2023-06-30 13:16:08
- astick360
- Member
- Registered: 2022-05-05
- Posts: 23
Display an article from the active section for the selected category
How to display an article only for a selected article category for an active section? I tried the <txp:article> tag but it doesn’t seem to work with article categories.
For the </txp:article_custom> tag, the categories work without a problem, but then I don’t know how to refer that it applies only to the active section.
Offline
#2 2023-06-30 13:47:08
- astick360
- Member
- Registered: 2022-05-05
- Posts: 23
Re: Display an article from the active section for the selected category
I encountered one more problem: how to make <txp:custom_field> dependent on the category of the article, also for the current section the visitor is in.
Offline
Re: Display an article from the active section for the selected category
astick360 wrote #335526:
How to display an article only for a selected article category for an active section? I tried the <txp:article> tag but it doesn’t seem to work with article categories.
It should do, it’s context sensitive. Hmm. What is the trailing part of the URL of the page you’re trying to display with the category selected? It should be something like /category/your-cat-name-here
.
Things to check:
- The permlink URL format of the section (Presentation>Sections panel)
- The form or container content you’re using in the article. Make sure it reflects the current article and section, and there’s no other contained tags that may interfere with the article’s context sensitivity (e.g.
<txp:section_list>
) - Your Admin>Diagnostics panel to check if pretty URLs are working and there are no other warnings that might affect it.
For the </txp:article_custom> tag, the categories work without a problem, but then I don’t know how to refer that it applies only to the active section.
<txp:article_custom section='<txp:section />'>...
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
Re: Display an article from the active section for the selected category
astick360 wrote #335527:
how to make <txp:custom_field> dependent on the category of the article, also for the current section the visitor is in.
On the admin side, this is currently not possible, sorry. In some future version of Textpattern, this is kind of planned (probably with a helper plugin) but for now you’ll need a plugin to do this.
However, if you want to display different field contents on the website based on the section and/or category then you can use conditionals:
<ul>
<txp:if_section name="events">
<li>Where: <txp:custom_field name="location" /></li>
<li>What to bring: <txp:custom_field name="essentials" /></li>
<li>When: <txp:custom_field name="start_date" /></li>
...
<txp:if_category name="residential">
<li>Extras: <txp:custom_field name="overnight_kit" /></li>
<txp:else />
<li>That's it!</li>
</txp:if_category>
</txp:if_section>
</ul>
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
#5 2023-07-02 04:54:54
- astick360
- Member
- Registered: 2022-05-05
- Posts: 23
Re: Display an article from the active section for the selected category
Thank you for your answer. First problem solved, works as it should.
As for the second one, I don’t think I wrote it well enough, sorry.
It’s about the condition that for the current section, from an article that has a category, e.g. residential, will display the content of the custom field of this article, e.g.: <txp:custom_field name=“location” />.
Such a condition needs, I tried to somehow convert what you gave but I don’t think I have enough skills. Please help me how it should look like.
Offline
Re: Display an article from the active section for the selected category
Ah, hang on. My mistake. Try using <txp:if_article_category>
instead of <txp:if_category>
in your article form. That will check the assigned category to the article, not the one in the URL.
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
#7 2023-07-02 14:12:02
- astick360
- Member
- Registered: 2022-05-05
- Posts: 23
Re: Display an article from the active section for the selected category
I couldn’t figure out why it wasn’t working until I noticed the keyword: article form. So what’s going on, I have this code based on what’s above and it works:
<txp:if_section name='<txp:section />'>
<txp:if_article_category name="1">
<txp:custom_field name="menu" />
</txp:if_article_category>
</txp:if_section>
The problem is that only in the article form. And here’s my next mistake because I assumed that it doesn’t matter where I want to display this information.
I don’t want the field: <txp:custom_field name=“menu” /> after meeting the above conditions, to be displayed in the form of this article, only the name of the link in the menu form.
Can it be done?
Offline
#8 2023-07-04 12:54:20
- astick360
- Member
- Registered: 2022-05-05
- Posts: 23
Re: Display an article from the active section for the selected category
Does anyone know if this is possible and if so, how?
Offline
Re: Display an article from the active section for the selected category
Not quite sure I grasp what you want here, but if you are after custom field information, it’s only available in article context i.e. inside an article form or container called by a <txp:article>
or <txp:article_custom>
tag.
It follows that conditional tags that rely on article content (such as <txp:if_article_category>
) will not work ‘outside’ of an article context either.
So if you want to display custom field content in any other places, you need to wrap your custom field code in an article (or article_custom) tag to trigger article context.
Hope that helps.
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
Re: Display an article from the active section for the selected category
try
<txp:if_section name='<txp:section />'>
<txp:if_article_category name="1">
<txp:if_custom_field name="menu">
<txp:permlink><txp:title /></txp:permlink>
<txp:hide>or anything you want here</txp:hide>
</txp:if_custom_field>
</txp:if_article_category>
</txp:if_section>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#11 2023-07-05 03:55:26
- astick360
- Member
- Registered: 2022-05-05
- Posts: 23
Re: Display an article from the active section for the selected category
Thanks for your help, it finally works. The code Bloke and colak correct of course, but the key was the suggestion Bloke that is, placing it in the <txp:article_custom> tag. Thanks for the help everyone again, maybe trivial but I don’t know if I would have figured it out or how long it would have taken me.
Offline