Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 Yesterday 20:32:50
- BryanA.
- Member

- From: Maryland, USA
- Registered: 2007-08-12
- Posts: 108
Utilizing Txp's two-view state
I’m a visual guy so code / PHP take a long time to ‘stick’ well enough for me to really get it. Textpattern has long mystified me with an elementary “else” knowledge that it uses to know a visitor’s list state vs the article state. That really confounds me – I’m anxious to go big and design different list page styles and when I’m also interested in designing different headers and calling different styles for specific article types, I get really stumped how to do that gracefully .
To the point: If I’m Publishing three vastly different post types, what tag or section or page do I use (from the Content > Write tab perhaps) as the cue for triggering the matching style a) per article, and b) per listing of said tag or section or page? I hope that’s easy as questions go! Thanks.
Voice Actor – now flirting with starting a new food blog. BryanDoesBooks in some spots
Offline
Re: Utilizing Txp's two-view state
As with most things Txp there are various ways to approach this. And it depends on how you want visitors to navigate your site.
Sections + Pages
Use a different page template per section, and post your articles in the relevant section. The <txp:article> tag in each template contextually switches between list/individual_article mode and you can use conditional tags <txp:if_article_list> and <txp:if_individual_article> in your associated Pages/Forms to style each layout differently. Or share various common traits to keep maintenance overheads lower.
Conditionals
If your articles are all in the same section (or even if they’re not!) you can use categories to differentiate. Create 3 different Article categories representing each post type and then choose that ‘flavour’ when you create the article, using (for example) Category1. Then in your page templates, as well as using the if_individual_article/if_article_list conditionals, you can use:
<txp:if_article_category number="1" name="x">
// Formatting for type 'x'
<txp:else />
<txp:if_article_category number="1" name="y">
// Formatting for type 'y'
<txp:else />
<txp:if_article_category number="1" name="z">
// Formatting for type 'z'
</txp:if_article_category>
</txp:if_article_category>
</txp:if_article_category>
Override forms
Getting cleverer, you can define a Form that governs the layout of each article type. In Prefs, you can define which Form type(s) are allowable as overrides during article creation. So let’s say you go to Advanced Prefs (which needs toggling on first) and define a new Form Type called “ArticleStyle”, and you make that available from Override form types in your Publish prefs.
Create a Form with tags how you want that type of content laid out and save it as some name under the ArticleStyle group. Repeat for each article type. You can still use the conditionals to flip between layouts for list/individual article.
Then, when you create an article, twist down the Sort and Display area and choose the relevant ArticleType from the list. That article’s content will be diverted through the nominated form.
There are other combinations or approaches (e.g. using a custom field as a switch) but they’re just variants of the above. Hope that gives you some ideas.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Pages: 1