Feeds

CMS: Using conditional template tags with Textpattern

PerformancingAds
Submitted by Markus Merz on March 3, 2008 - 4:37pm in

Raj stated: "You seem to despise WordPress, even though it's better than TextPattern ;)"

  • Well, are you developing themes for WordPress?
  • Do you want content being different depending on page, category, keyword, article, tag, list, sub-directory,...?
  • Do you have to write documentation for client projects?

The Textpattern CMS/blog system offers a great set of template tags!

In the development process of a website/blog time is an important issue. Doing website development for clients also means to have the ugly task to write a documentation. I am not sure how website development with WordPress is done but I can show you how easy it is to develop a content driven website with Textpattern and achieve a nice logical overview (plus easy documentation).

Let's see how to realize different sidebars dependent on the single output page...

Develop but watch the ROI

In New Niche Blog: Develop a content driven concept FAST one point was "Phase Two: Rough content sketches". Another important issue in website development is the 'return of investment trap'.

If you are one of those guys who say 'I will keep all my options open' then you may end up investing more time than the site will pay back to you regarding monetization.

If you are on tight budget this also means that fiddling around with PHP core code can eat up a lot of your time resources. Raj also stated in 48 Unique Ways To Use WordPress:

WordPress, one of the most popular blogging platforms (if not the most), is capable of being more than just a blog platform. It's capable of being a full-blown CMS (Content Management System). As someone who has both written small, custom CMSes from scratch as well as evaluated million-dollar professional CMSes for large corporations, WordPress' robustness never ceases to amaze me.

This is a mouthful of WordPress evangelism, isn't it?

For sure there are millions of possibilities to combine ready made WordPress themes and plug-ins. But please keep in mind that the core features of a CMS must fulfill the needs for web development. IMHO it makes no sense to blow up a simple and working blog system with multiple plug-ins to achieve what other CMS deliver out of the box. I am not even talking about performance, security risks and counting database queries.

The more you have to hack core files the more faithless and even unstable the solution will be in the long run!

The Textpattern if/else way

For rapid content development combined with the effort to reduce the available content to the minimum I love the ease of conditional Textpattern if/else template tags. Of course there are many more if/else template tags available via different plug-ins.

One of the most important plug-ins for stripping down content is the <txp:chh_if_data> tag. Simple sense: (No) data = (no) output. Advanced sense: No data = different output. With this conditional tag empty content boxes are gone.

Always having the same sidebar reduces attention and CTR.

I use different sidebars for article lists and single articles. This can be tuned furthermore i.e. for keyword or search pages where I am able to create service offers depending on the search phrase or the keyword. On more advanced sites I also use single article IDs as a conditional element i.e. to pull in different feeds from a central Textpattern form as I described it in Blog archive: The publishing power of bookmarks.

Textpattern if/else code example for a sidebar

In Textpattern the template code base is pretty easy. In the specific case I created a Textpattern form element 'sidebar' which is included in the main page template via <txp:output_form form="sidebar" />. To be prepared for future refinements the form is a template by itself covering multiple if/else situations in advance. I added some documentation comments:

<div id="sidebar">
<txp:if_individual_article>
<txp:output_form form="sidebar_related_articles" />
<txp:output_form form="sidebar_newest_articles" />
<txp:else />
<!-- Shows up everywhere except if_individual_article -->
<txp:output_form form="pagination" />
<txp:popup label="Categories" wraptag="p" type="c" />
<txp:if_search>
<txp:output_form form="sidebar_search_alternatives" />
<txp:output_form form="sidebar_newest_articles" />
<txp:else />
<txp:if_category>
<txp:output_form form="sidebar_newest_articles" />
<txp:else />
<!-- Shows up only on homepage -->
<txp:if_section name="default"><txp:output_form form="home_skyscraper" /></txp:if_section>
<txp:if_section name="section1, section2, section3"><txp:output_form form="sidebar_newest_articles" /></txp:if_section>
<!-- Add more txp:if_section conditions if necessary -->
</txp:if_category>
</txp:if_search>
</txp:if_individual_article>
<!-- Shows up everywhere -->
<txp:output_form form="google_160x600" />
</div>

As you can see I am using <txp:output_form form="sidebar_newest_articles" /> multiple times but can of course tune every condition furthermore if I like. The txp:output_form Textpattern template tag is an awesome possibility to structure, reuse and refine Textpattern content without loosing the overview.

Textpattern project documentation

As you can see in the code example above it is easy to simply print the form or to even transfer the if/else logic into a nice flowchart. If you love flowcharts and you do a lot of projects then it is a good idea to have a flowchart library for all those single if/else tags.

A project containing many different pages and complex page dependent if/else structures must be documented. Otherwise maintenance, support and future development is pretty difficult to realize. Four weeks after handing over a website to a client I will have forgotten how I built the structure but then the questions will probably start to trickle in. Handing over a printed documentation to the client and having the code available will keep discussion to a minimum.

The reaction time and the duration of a support call is your time too. Are you getting paid for those 'just a little question' support calls?

One last (easy) CMS task

A friend of mine has a record studio. He has a classic static HTML website organized in sub-directories. How do you transfer this simple site into a WordPress site with the same look and functions but totally controlled with WordPress? I have promised to realize it in two (paid) hours with Textpattern. Oh, overtime is my problem.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <h2> <h3> <h4> <img> <div> <a> <em> <strong> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <span> <table> <td> <tr> <caption> <th> <hr> <pre> <br> <p> <object> <param> <embed> <strike>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 15 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.