Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Dictating category links order
I have been trying to prioritise the order in which category links appear in a menu, as some are more important that others.
I am able to do this by using custom_field, the lower the number the higher the link appears in the list.
The problem
If a content editor forgets to add a number to an article, then these links go right to the top… grrrrr.
Desired effect
What i want is if the editor forgets to add a number in the custom field, or the order is for thsi item unimportant, then that link should placed below the order links. I’ve tried loads of different approaches which i won’t bore you with at this stage, but suffice to say i haven’t got it working yet.
<txp:if_article_category name="my-cat-name">
<txp:if_custom_field name="related_links_order">
<txp:article_custom form="MTS_article_list" sort="custom_3 asc" category="my-cat-name" offset="1" />
</txp:if_custom_field>
</txp:if_article_category>
Can anyone offer some advice?
Last edited by Timid&friendly (2009-05-15 16:53:09)
I think, therefore I AM, … … er … I think :-?
Offline
#2 2009-05-15 19:27:42
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Dictating category links order
Timid&friendly wrote:
the order in which category links appear in a menu
Am I right in assuming you are talking about links to articles, not to categories? And your code is inside an article form, displaying links to articles in the same category as the current article? In that case this conditional:
<txp:if_custom_field name="related_links_order">
is not going to work, because it only looks at the custom field value for the current article. What is in your form ‘MTS_article_list’?
Offline
Re: Dictating category links order
Yes you are correct in that these links are indeed links to articles and not to categories.
<li>
<txp:permlink><txp:title /></txp:permlink>
</li>
This does work in ordering the links, Only the unorder (articles with an empty value for <txp:if_custom_field name="related_links_order">
get put first before the ordered links and i want the last.
I think, therefore I AM, … … er … I think :-?
Offline
Re: Dictating category links order
Simplest solution is to reverse the sort order and use high numbers for high priority.
Code is topiary
Offline
#5 2009-05-16 14:03:38
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Dictating category links order
jsoo wrote:
Simplest solution is to reverse the sort order and use high numbers for high priority.
Great! So simple that I didn’t think of it ;) Just in case there is a reason you can’t use jsoo’s solution, I wonder if this works:
<txp:article_custom sort="custom_3 asc" category="my-cat-name">
<txp:if_article_id>
<txp:else />
<txp:if_custom_field name="related_links_order">
<li>
<txp:permlink><txp:title /></txp:permlink>
</li>
</txp:if_custom_field>
</txp:if_article_id>
</article_custom>
<txp:article_custom category="my-cat-name" related_links_order="">
<txp:if_article_id>
<txp:else />
<li>
<txp:permlink><txp:title /></txp:permlink>
</li>
</txp:if_article_id>
</txp:article_custom>
It’s calling two article lists, first the articles that have a sort value, and then the articles that don’t.
It’s possible that you need to wrap the entire block in <txp:if_individual_article>
tags, for the <txp:if_article_id>
(don’t display the current article) to work.
Offline
Re: Dictating category links order
Thx jsoo very much to you two, …excuse the bad pun :-P
I thought about reversing the sort order but then content editor would have to think, and thinking cost time and is extra hassle for them, but thx for the suggestion.
Els tried your approach, it didn’t work in my context, NP i’ll figure it out in the end :-)
But do have two questions:
1. Why did you use the <txp:if_article_id>
tag, am i right in thinking that this would stop the rendering of the current article link?
2. In the second group tag <txp:article_custom category="my-cat-name" related_links_order="">
you use the ... related_links_order=""...
as an attribute of the article_custom
tag. Is that allowed ? surely not.
Last edited by Timid&friendly (2009-05-16 18:19:18)
I think, therefore I AM, … … er … I think :-?
Offline
#7 2009-05-16 18:35:09
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Dictating category links order
Timid&friendly wrote:
1. Why did you use the
<txp:if_article_id>
tag, am i right in thinking that this would stop the rendering of the current article link?
Yes, you are right. I’m using similar code on a site to display article excerpts in the sidebar. For individual article pages I wanted to exclude the current individual article from the list in the sidebar. Maybe it works differently if you have this code in an article form (I don’t know what other code you have in there), but I placed this code on the page and it didn’t work without surrounding if_individual_article tags.
2. In the second group tag
<txp:article_custom category="my-cat-name" related_links_order="">
you use the... related_links_order=""...
as an attribute of thearticle_custom
tag. Is that allowed ? surely not.
If your custom field is named ‘related_links_order’, it’s definitely allowed :) If you look at the Textbook tag page you will see an attribute customfieldname
: “Restrict to articles with specified value for specified custom field name. Replace “customfieldname” with the name of the custom field.”
Els tried your approach, it didn’t work in my context, NP i’ll figure it out in the end :-)
It’s possible that it’s not quite right, I didn’t test it. Did you try to place the code directly on the page?
If you don’t figure it out, let me know!
Last edited by els (2009-05-16 18:36:15)
Offline
Re: Dictating category links order
Kind of clunky, but:
<txp_article_custom sort="custom_3 asc" category="my-cat-name" offset="1">
<txp:if_custom_field name="related_links_order">
<txp:else />
... article display tags here ...
</txp:if_custom_field>
</txp:article_custom>
<txp:article_custom related_links_order="" category="my-cat-name" offset="1">
... article display tags here ...
</txp:article_custom>
Of course you could use forms instead of article_custom
as containers. Idea being the first list excludes articles with nothing in the relevant custom field, then the second list has only those articles. I don’t know if it’d work as written, but it’s an idea.
Code is topiary
Offline
Re: Dictating category links order
I’ll check it out thx for your ideas
I tried them with no success. BUT that’s probably because i miss read Els’s comments and give you guys the wrong response … GRRRR pls forgive me ^^
Els wrote:
Am I right in assuming you are talking about links to articles, not to categories? And your code is inside an article form, displaying links to articles in the same category as the current article?
1. My code is on a section page, nested in an <txp:if_individual_article>
tag, and not in an article form.
2. It is indeed displaying linked titles to articles in the current category
Last edited by Timid&friendly (2009-05-19 19:11:24)
I think, therefore I AM, … … er … I think :-?
Offline
Re: Dictating category links order
I confess i am very frustrated now :-(
No matter what i try and in whatever context i work, wether section page or article form i get the same results.
1. Success I can easily output only the articles with an empty custom_field.
2. Failure I can not separate articles with empty custom_field from articles with used custom_fields, (the empty custom_field articles are allows rendered as well).
It seems that this isn’t possible?
I think, therefore I AM, … … er … I think :-?
Offline
Re: Dictating category links order
Okay, I think I’m understanding the dimensions of the problem a bit better now. I can see why my second solution failed — the if_custom_field
checks against the current article context, not the articles produced by article_custom
, which of course have no context. Only reasonable solutions I can see are my first suggestion or making an article_custom
plugin to handle this situation.
Code is topiary
Offline
#12 2009-05-21 12:22:24
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Dictating category links order
Timid&friendly wrote:
2. Failure I can not separate articles with empty custom_field from articles with used custom_fields, (the empty custom_field articles are allows rendered as well).
Hmm… that’s strange. Give me some time and I’ll try and test that.
Offline