Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-03-08 12:48:49
- mnewboult
- New Member
- Registered: 2010-01-05
- Posts: 5
Redirect to article if there's only one article in a given category
I have the requirement to display a list of categories. Articles are all tagged with a specific category. If the user clicks a category with > 1 article, they need to see the list of articles to choose from. However if there’s only one article for that given category I need to redirect the user to that article – they shouldn’t have to choose anything.
Does anyone know if there’s a plugin for that?
Thanks
Offline
Re: Redirect to article if there's only one article in a given category
You shouldn’t need a plug-in for this, I think. See Els’ TXP tip here. Look at the section of her code headed by <!— check if there is more than one article in this section —>. You can readily adapt this method to identify article categories with only one article instead of sections with only one article.
Offline
Re: Redirect to article if there's only one article in a given category
Some tiny example without plugins:
<txp:variable name="count" value="0" />
<!--
Count done with article_custom and variables.
-->
<txp:article_custom category='<txp:category />' limit="2">
<txp:if_first_article>
<txp:variable name="count" value="1" />
<txp:else />
<txp:variable name="count" value="2" />
</txp:if_fist_article>
</txp:article_custom>
<!--
Check the results from the contents of "count".
-->
<txp:if_variable name="count" value="1">
<!--
Fetch permlink.
-->
<txp:article_custom category='<txp:category />' limit="1">
<txp:php>
header(
'Location: '.permlink(array())
);
</txp:php>
</txp:article_custom>
</txp:if_variable>
Added some comments to the code. Hope it helps.
Offline
#4 2010-03-08 14:42:35
- mnewboult
- New Member
- Registered: 2010-01-05
- Posts: 5
Re: Redirect to article if there's only one article in a given category
Thank you very much. Worked a treat. Just starting to get under the bonnet (hood) of txp and find this kind of help very much appreciated.
The only bit about the above example I don’t get is:
header(
‘Location: ‘.permlink(array())
);
Offline
Offline