Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-07-26 16:58:08

jensf
Member
Registered: 2015-07-16
Posts: 23

How can I show Category 2 outside an article context?

Hi,

Please have a look at my a site I’m currently working on: http://frickeln.jensfreyer.de/ (I guess it’s the easiest way to get the issue I’m struggeling with. Please go to the navigation bar “Reisen” | “Deutschland” | …

I’m trying to create a kind of a “dynamic” navigation which depends on available categories. For “Deutschland” all children categories (category2) are shown according to that piece of code:

<txp:category name="deutschland" title="1" link="1" />                      
<txp:category_list class="dropdown" parent="deutschland" sort="name asc" wraptag="ul" break="li" />

But that’s not what I actually want to do. My intension is to show a list of category2 if available for the shown Category 1 (= “Deutschland”). But all previous attempts failed with the TXP error information “Article tags cannot be used outside an article context”.

Is there any way to show all “children” of e.g. the Category 1 = “Deutschland” if existing outside an article context!?

Your ideas are very appreciated! Thanks in advance!

Cheers!

Jens

Last edited by jensf (2015-07-27 07:07:20)

Offline

#2 2015-07-26 20:58:34

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: How can I show Category 2 outside an article context?

Hello,

you can fake an article context, but check first if this does what you want (lowercase is intentional):

<txp:article_custom category="deutschland" sort="Category2" limit="999" wraptag="ul">
	<txp:if_article_category number="2">
		<txp:if_different>
			<li><txp:category2><txp:category2 title="1" /></txp:category2></li>
		</txp:if_different>
	</txp:if_article_category>
</txp:article_custom>

This assumes “Deutschland” is used only as Category1, and in this case Category2 is a child of “Deutschland”, but this assumption can be relaxed.

If you have really many articles, a specialized plugin could be faster.

Edit: another possibility, assuming the children of “Deutschland” are never in Category1:

<txp:category_list class="dropdown" parent="deutschland" exclude="deutschland" children="0" sort="name asc" wraptag="ul" break="">
	<txp:article_custom category='<txp:category />' limit="1" wraptag="li">
		<txp:category2><txp:category2 title="1" /></txp:category2>
	</txp:article_custom>
</txp:category_list>

Edit: looking at your site, perhaps you just want to exclude the parent from the list?

<txp:category_list class="dropdown" parent="deutschland" exclude="deutschland" children="0" sort="name asc" wraptag="ul" break="li" />

Last edited by etc (2015-07-26 21:48:31)

Offline

#3 2015-07-26 22:57:55

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: How can I show Category 2 outside an article context?

adi_menu may do something for you. It’s predominately section-based but there’s a soon to be released version that gives you options to build in categories as well.

If you’d like to give it a go, contact me on forum email.

Offline

#4 2015-07-27 16:21:10

jensf
Member
Registered: 2015-07-16
Posts: 23

Re: How can I show Category 2 outside an article context?

Thank you very much for your comments and very useful hints… or better: solutions!

@etc,
You’re so right with your last thought to add the “exclude” attribute to category_list which eliminates the double listing of Category1… as the solution I was searching first.

But the other possibilities are really great solutions (for me): my favorite is possibility # 2 – the category_list with children=“0” attribute. This and # 1 are much better than to exclude parent category1 only because the navigation becomes really “dynamic” when sub navigation entries are availabe not before there is any content.

@gomedia,
Thanks for your hint! I’ll follow-up with the discussed possibilities here for now. But I am very interested in the plugin, too!

Thanks again!

Jens

Last edited by jensf (2015-09-09 07:19:46)

Offline

#5 2015-07-28 12:12:52

jpdupont
Member
Registered: 2004-10-01
Posts: 752

Re: How can I show Category 2 outside an article context?

Hello Adi, interested by the new adi menu too ! Thanks.

Offline

#6 2015-08-05 02:32:08

wavesource
Member
From: Australia
Registered: 2011-08-02
Posts: 56

Re: How can I show Category 2 outside an article context?

adi_menu rocks – this sounds like a great development

Offline

#7 2015-08-05 05:00:40

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: How can I show Category 2 outside an article context?

jensf wrote #293701:

Hi,

Please have a look at my a site I’m currently working on: http://frickeln.jensfreyer.de/ (I guess it’s the easiest way to get the issue I’m struggeling with. Please go to the navigation bar “Reisen” | “Deutschland” | …

I’m trying to create a kind of a “dynamic” navigation which depends on available categories. For “Deutschland” all children categories (category2) are shown according to that piece of code:

<txp:category name="deutschland" title="1" link="1" />...

But that’s not what I actually want to do. My intension is to show a list of category2 if available for the shown Category 1 (= “Deutschland”). But all previous attempts failed with the TXP error information “Article tags cannot be used outside an article context”.

I wonder if you are confusing Category 1/Category 2 with Parent Category/Child Category. If Reisen is the parent category and Deutschland, Frankreich etc are child categories then see Els’ TXP tip here.

Here it is from one of my sites which lists cars for sale by Marque in the navigation. This one excludes ‘empty’ parent Marques categories that have no Car child categories

<nav>
	<txp:category_list wraptag="div" break="" parent="marques" exclude="marques children="0" class="top-category">
		<div class="inter-category">
			<h3><txp:category title="1" /></h3>
			<txp:category_list parent='<txp:category/>' exclude='<txp:category/>' children='0' wraptag="ul" break="li">
					<txp:variable name="morethanone" value='<txp:article_custom category=''<txp:category />'' limit="1" offset="1" />' />
						<txp:if_variable name="morethanone" value="">
   							<txp:article_custom category='<txp:category />' limit="1" ><txp:permlink><txp:category1 link="0" title="1"/></txp:permlink></txp:article_custom>
							<txp:else />
							<txp:category title="1" link="1" section="cars"/>
						</txp:if_variable>
   			</txp:category_list>
		</div>
	</txp:category_list>
</nav>

Last edited by joebaich (2015-08-05 05:03:43)

Offline

#8 2015-09-09 09:34:23

jensf
Member
Registered: 2015-07-16
Posts: 23

Re: How can I show Category 2 outside an article context?

joebaich wrote #293957:

I wonder if you are confusing Category 1/Category 2 with Parent Category/Child Category. If Reisen is the parent category and Deutschland, Frankreich etc are child categories then see Els’ TXP tip here.

Here it is from one of my sites which lists cars for sale by Marque in the navigation. This one excludes ‘empty’ parent Marques categories that have no Car child categories

<nav>...

Hi joebaich,

Thank you for your tips and detailed example of your solution for an “active” site navigation.

To be honest, I’m still a beginner with Textpattern… but I didn’t see to mix sth. up with Categories and Parent/Children.
I simple came from the Textpattern backend => Content | Write [Sort and display]… where I can select a value from the picklist for “Category 2” for an article: my intention is to show the choosen value for “Category 2” in a kind of “sub navigation” sorted below the “top level” navigation as given with the choosen value for “Category 1”, e.g.:

<li class="has-dropdown">                                                                                                      
 <txp:category section="blog" name="deutschland" title="1" link="1" />
 <txp:category_list class="dropdown" parent="deutschland" exclude="deutschland" children="0" sort="name asc" wraptag="ul" break="">
  <txp:article_custom category='<txp:category />' limit="1" wraptag="li">
   <txp:category2 section="blog"><txp:category2 title="1" /></txp:category2>
  </txp:article_custom>
 </txp:category_list>
</li>

This code generates the linked “sub navigation” Schwarzwald in my top navigation => “Reisen” | “Deutschland” |…

I tried sth. out without using Category2 in order to get the children shown in the navigation, e.g. “Deutschland” is configured as the parent of “Schwarzwald” in Textpattern… but unfortunately, I don’t get “Schwarzwald” shown with category_list structures alone.

Offline

Board footer

Powered by FluxBB