Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-04-19 18:31:11
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Display a link to a certain page, if category is..
How to display a link to a certain page, if category is ‘X’ ?
thanks
Bongo-man
Offline
Re: Display a link to a certain page, if category is..
hi Bongo-man
You can try
<txp:if_category name="X">
<p><a href="#link">a link to a certain page</a></p>
</txp:if_category>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2009-04-20 20:46:58
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Re: Display a link to a certain page, if category is..
I Thank ypou for your useful answer: it works (without # before the link); but, can I write in the template a sequence of <txp:if_section> or a sequence of <txp:if_category> like this:
<txp:if_category name=“X”>
<p><a href=”#link”>a link to a certain page</a></p>
</txp:if_category>
<txp:if_category name=“Y”>
<p><a href=”#link”>a link to a certain page</a></p>
</txp:if_category>
<txp:if_category name=“Z”>
<p><a href=”#link”>a link to a certain page</a></p>
</txp:if_category>
<txp:if_category name=“A”>
<p><a href=”#link”>a link to a certain page</a></p>
</txp:if_category>
<txp:if_category name=“B”>
<p><a href=”#link”>a link to a certain page</a></p>
</txp:if_category>
etc. ?
Can it work?
Offline
#4 2009-04-20 20:58:01
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Display a link to a certain page, if category is..
You can use as many instances of if_category and/or if_section as you wish, but if there are really many of them, it would be nice to find a way to automate things. Are these pages you are linking to part of your Txp site or external links?
Last edited by els (2009-04-20 20:58:32)
Offline
#5 2009-04-20 21:38:47
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Re: Display a link to a certain page, if category is..
They are external links. In other case would it have been possible to automate?
How does it work automation?
Do many ‘txp:if_….’ slow the activity of a template in printing pages?
I thank you for your answer.
Offline
#6 2009-04-20 22:17:53
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Display a link to a certain page, if category is..
If each category page needs a different external link, I think you could automate it like this:
- create exactly the same link categories as your article categories (in Content > Categories)
- enter your external links in the Links tab, and assign the category that matches the article category where you need to display it
- on your page, use this code:
<txp:if_category>
<txp:linklist category='<txp:category />'>
<p><txp:link /></p>
</txp:linklist>
</txp:if_category>
This way, on every category page, the link(s) that has/have the same category as the currently viewed category will be displayed. Instead of <txp:link />
you can of course use one or more of the other link tags if you prefer.
If you only want to display the links on some category pages, but not all, you can change <txp:if_category>
to <txp:if_category name="X,Y,Z,A,B">
.
I don’t know if many conditional tags will slow a page down; probably slightly, but I’m using lots of conditionals myself and I don’t think these pages are noticeably slow.
Offline
#7 2009-04-21 16:25:24
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Re: Display a link to a certain page, if category is..
I’m sorry I would like to know an other (related) thing:
If I wanted, with this statement,
<txp:if_category name=“X”>
<txp:linklist category=‘X-links-category’>
<p><txp:link /></p>
</txp:linklist>
</txp:if_category>
have displayed only one random link in the ‘X-links-category’ is there any rule to get this?
Thanks
Bongo-man
Offline
Re: Display a link to a certain page, if category is..
According to the textbook this might work
<txp:if_category>
<txp:linklist category='<txp:category />' sort="random" limit="1"">
<p><txp:link /></p>
</txp:linklist>
</txp:if_category>
Last edited by colak (2009-04-21 16:56:25)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#9 2009-04-21 17:27:00
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Re: Display a link to a certain page, if category is..
I’ thank you very much for you answers.
Bongo-man
Offline
#10 2009-04-23 19:26:59
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Re: Display a link to a certain page, if category is..
I’m sorry I’ve tried all above, but does not work.
What I need is to display not a unique link list, but a certain link list:
If the category is this, the link list is this other.
If the category is an other, the link list, change.
And so on.
I’ ve created many link list with external links directed to those page of my site I couldn’t put, till now, in the blog, but I couldn’t what I need.
Must I begin with:
<txp:else /> ?
In that case can I use many time else?
- An other option for the error could be in the way I substituted category=’<txp:category />’ with the link cathegoy name. Do I use ‘’ , or “” ? … and ‘txp:category’ is the name of the link category, I need to insert here?
Last edited by Bongo-man (2009-04-23 19:56:40)
Offline
#11 2009-04-23 20:55:38
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Display a link to a certain page, if category is..
Don’t replace <txp:category />
in category='<txp:category />'
with the category name. The tag is context sensitive so it will use the category that is currently being viewed. The trick is that you have to use exactly the same category names for your links as for your articles, so that when you are on (article) category page ‘x’ it will display the links in link category ‘x’, etcetera. You also need to make sure that you don’t use capitals in category names. So if the names are really ‘X’ and ‘Y’, change them to ‘x’ and ‘y’.
If I understand correctly what you want to do – when on a category page, display the corresponding linklist, except when on category page ‘x’, then display a random link – this code will do it:
<txp:if_category>
<txp:if_category name="x">
<txp:linklist limit="1" sort="rand()">
<p><txp:link /></p>
</txp:linklist>
<txp:else />
<txp:linklist category='<txp:category />'>
<p><txp:link /></p>
</txp:linklist>
</txp:if_category>
</txp:if_category>
Offline
#12 2009-04-23 23:28:43
- Bongo-man
- Member
- Registered: 2009-03-18
- Posts: 243
Re: Display a link to a certain page, if category is..
Ok all is clear and the second part of your answer is not necessary for my problem, but it is useful to understand also this kind of issues.
The only useful thing I can see also in this expression is the attribute sort=“rand()”, that also in the textpattern guide is reported in this way instead of sort=“random”, as you said last time.
Another thing <txp:linklist category=’<txp:category />’>is not clear with respect to the guide. It uses these “ “, instead of ‘ ‘ for object of this expression, as follows:
<txp:linklist category=”<txp:category />”>
Offline