TXP Current Navigation

— Topic: Content Management

From time to time, I see in my Mint referral logs that people are still hitting my article on Templating in Textpattern. I won’t go into incredible detail here, since you can just read it for yourself. I just wanted to touch on the navigation portion of that article, because I now use a different method. Previously, I was unknowingly doing something similar to Jon Hicks, but realized recently that there’s a far easier way to do it, which requires considerably less CSS.

So, if you feel like it, read through that old post, and then compare the code provided to the way I do things in Textpattern now. Initially, I was going to post the code right here, but since it gets far too long and line-wraps, I will just provide you a link to a text file, containing the appropriate TXP code. As you can see, that turns out to be a horrible looking mess. However, the way that Textpattern parses its own tags, it actually turns out nice and tidy.

When Textpattern sees a tag that begins with txp:, it will automatically replace it with the appropriate HTML. In this case, let’s say for the section of my site named journal, it finds it and replaces the code contained therein. If the current section is not Journal, it will simply replace the whole mess of TXP code with nothing instead. On my index page, there is nothing selected. This way, instead of having a ton of ID or class names added to your body tag, you can just have a simple bit o’ CSS that only styles the current section.

#nav a.current {
  /* Your code here */
}

Hopefully this will help you out. Sorry for taking so long to write this. I feel bad because I know someone probably did it the old way, and it could’ve been avoided if I wasn’t so lazy in putting off writing this post. Anyway, go forth, and have cleaner HTML and CSS, making Textpattern do the heavy lifting.

Powered by Fusion Ads
 

JS Tutorial, JavaScript Tutorial, JavaScript Guide, Learn JavaScript JS, How To Learn JS, Learning JavaScript
Promote JavaScript


Disclaimer

The thoughts and opinions expressed here are mine alone, and are not necessarily shared by any other living person.