Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-04-11 18:04:19

anteante
New Member
Registered: 2012-04-11
Posts: 9

Navigation structure: Section - Category - Article

Hello forum,

for a current project, I am trying to achieve the following navigation structure:

  • Section I
    • Category A
      • Article 1
      • Article 2
      • Article 3
    • Category B
    • (… more categories …)
    • Category Z
  • Section II

etc.

As there are only 2 main sections, I don’t mind keeping the navigation links to the section ‘static’. For the generation of the category-article structure I am using this form:

<txp:category_list parent="parent" exclude="parent" wraptag="ul" break="li" >
<!-- var for active category class -->
<txp:variable name="catclass" value="passive" />
<txp:if_category name='<txp:category />'>
<txp:variable name="catclass" value="active" />
</txp:if_category>
<!-- category name -->
<txp:category title="1" link="1" />
<!-- list all articles in this category -->
<txp:article_custom section="gruppen" category='<txp:category />' wraptag="ul" break="li">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
</txp:category_list>

(credits for this concept go here)

This works all very fine, with one major drawback: Links to all articles of all categories are displayed. This becomes very clumsy if you have say, 20 categories and 20 articles in each category. Therefor, I only want to display articles of the current category.

Obviously, I could wrap the article_custom bit in a <txp:if_category> conditional, but then the list of articles would not be displayed on an individual article page.

Is there a conditional statement I could use instead? I reckonthe solution is rather simple, but at the moment I am a bit stuck, so any advice is appreciated!

Last edited by anteante (2012-04-11 18:05:24)

Offline

#2 2012-04-11 19:36:53

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Navigation structure: Section - Category - Article

anteante wrote:

Obviously, I could wrap the article_custom bit in a <txp:if_category> conditional, but then the list of articles would not be displayed on an individual article page.

You can combine if_category, if_individual_article and if_article_category. Something like this:

<txp:if_individual_article>
   <txp:if_article_category name='<txp:category />'>
      // your code
   <txp:if_article_category>
<txp:else />
   <txp:if_category name='<txp:category />'>
      // your code
   </txp:if_category>
</txp:if_individual_article>

Offline

#3 2012-04-12 22:00:38

anteante
New Member
Registered: 2012-04-11
Posts: 9

Re: Navigation structure: Section - Category - Article

Dear Els,

thanks a lot for this hint, exactly what I was looking for. After some fiddeling, the full navigational structure is working now as supposed!

Offline

#4 2012-04-12 22:15:22

anteante
New Member
Registered: 2012-04-11
Posts: 9

Re: Navigation structure: Section - Category - Article

If this is of use for anyone, here is the full code I was using in order to achieve the mentioned section – category – article structure. (I reckon there might be more elegant or flexible solutions, but this is a starting point)

For each (static) section I was using this bit:

<li><a href="#">Section ⁄</a>
  <txp:if_individual_article>
  <txp:output_form form="cat-list-article" />
  <txp:else />
  <txp:output_form form="cat-list" />
  </txp:if_individual_article>
</li>

the cat-list form would be:

<txp:category_list parent='<txp:section />' exclude='<txp:section />' wraptag="ul" break="li" class="sidebar-level2">
	<!-- variable for active class -->
		<txp:variable name="catclass" value="passive" />
		<txp:if_category name='<txp:category />'>
		<txp:variable name="catclass" value="active" />
		</txp:if_category>
	<!-- category titles -->
	<txp:category title="1" link="1" class='<txp:variable name="catclass" />' />
	<!-- display articles of the current category -->
	<txp:if_category name='<txp:category />'>
		<txp:article_custom section='<txp:section />' category='<txp:category />' wraptag="ul" break="li" class="sidebar-level3">
			<!-- variable for active class -->
			<txp:variable name="artclass" value="passive" />
			<txp:if_article_id>
			<txp:variable name="artclass" value="active" />
			</txp:if_article_id>
		<!-- list articles -->
		<txp:permlink class='<txp:variable name="artclass" />'><txp:title /></txp:permlink>
		</txp:article_custom>
	</txp:if_category>
	</txp:category_list>

the cat-list-article form looks exactly the same, but with <txp:if_article_category> conditionals instead of <txp:if_category>

Credits for the basic concept go here and thanks again, Elz …

Offline

Board footer

Powered by FluxBB