Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-02-02 10:43:23
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
[howto] another way to build static/dynamic "sub nav"
I have recently built a couple of sites using this approach and thought I would post here for comment.
The set-up: a standard website with a few sections, each section containing one or more webpages that are mainly ‘static’, along with some ‘dynamic’ content (event items, blog posts – assigned as ‘live’ articles) incorporated within various sections. The sub nav should be dynamically built (as much as possible).
The concept: all ‘static’ content will be created as ‘sticky’ articles… a custom field (let’s choose Custom_10
) will be given the name “sort order” and used to order the sub nav list. The sticky article at position 01
will be the section’s introductory page.
Plugins used: rvm_if_this_article and asy_wondertag
Textpattern code for generating a sub nav, placed in a page template:
<ul id="subnav">
<li class="subnav-title"><txp:section title=1 link=1 /></li>
<txp:asy_wondertag><txp:article_custom status="sticky" section="<txp:section title=0 link=0 />" sort="Custom_10 asc" form="list-subnav" limit=999 offset=1 /></txp:asy_wondertag>
</ul>
Here’s the form called list-subnav
that’s called from the code above:
<li><a<txp:rvm_if_this_article> class="active"</txp:rvm_if_this_article> href="<txp:permlink />"><txp:title /></a></li>
Here’s more page template code that outputs the articles:
<txp:if_article_list>
<txp:article status="sticky" limit=1 sort="Custom_10 asc" />
<txp:else />
<txp:article status="sticky" />
<txp:article />
</txp:if_article_list>
- – - – - – - -
Nothing new really – Dynamic Sub Menu with active class is a recent tutorial on Textpattern Resources that follows a similar line – but I’m ‘hiding’ the first static article (my introduction to the section) from the sub nav by using offset=1
. In its place, I’m using the section title.
I don’t want /section/article-01
being accessible from the sub nav – I want the user to only ever see /section
.
The other advantage – I wanted the title of the sub nav to be the same as the section’s title
– but I wanted a different title atop the introductory article. This gave me more flexibility with copywriting.
Where I need to add some section-specific items to the sub nav (such as zem_event
categories), I added them within conditional tags (<txp:if_section>
) either above or below the article_custom
tag… again it seemed to balance hard-coding & dynamic nav for my situation.
There are plenty of hooks for styling. An active class on the current article can be used to show the visitor their place in the website, and the section title is also available for treatment.
The primary reason for this approach was having ‘event articles’ located within several of the sections. Note that a search result could still conceivably direct the user to /section/article-01
Offline
#2 2008-02-02 16:11:02
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [howto] another way to build static/dynamic "sub nav"
Thanks for this how-to. The use of the offset attribute is a clever and simple solution.
Note that a search result could still conceivably direct the user to
/section/article-01
You can forestall this with a RewriteRule in .htaccess.
Offline
#3 2008-02-05 00:46:33
- diniscorreia
- Member
- From: Lisbon, Portugal
- Registered: 2007-07-18
- Posts: 19
Re: [howto] another way to build static/dynamic "sub nav"
Great approach.
I recently did something similar – ‘brochure’ type website with several sections, each with several static articles. I’ve followed the ‘Dynamic Sub Menu with active class’ tutorial. Unfortunately, my client didn’t want an introdutory page – the section should jump to its first article. I had to manually set the primary nav to do this – not that classy!
You can forestall this with a“RewriteRule in .htaccess
Even better, use gbp_permanent_links :)
Last edited by diniscorreia (2008-02-05 00:46:58)
Offline