Wednesday January 19, 2005

Textpattern: Flexible Article Placement.

This article assumes that the reader has a general understanding of Textpattern semantics and building blocks, such as forms and page templates. Tested only on Textpattern 1.0rc1. See end of article for updates to Textpattern 4.0.

I have been wrestling with the implementation of static pages in Textpattern since I began working with it over 3 months ago. I read some tutorials, but they didn’t give me the ammunition I needed to resolve my particular issues.

Up until today, my About page was 100% hardcoded; that is, there wasn’t a stitch of Textpattern code in the template used for that page. I simply wrote straight HTML to fill in my content so that I could get it placed in the precise order I wished. As I have had some correspondence with people interested in using Textpattern for their business websites, I began realizing that while hardcoding might work swell for me, it could be endlessly confusing for someone with little or no knowledge of HTML. The answer, then, was to take all the content on my About page and move them into Textpattern articles. Articles don’t require any real HTML knowledge and are easily organized and editable by the average person through the Admin panel.

Looking at my About page, you can see that there are multiple articles. For example, the title “What Follows Is A Riveting Biography” and the text that accompanys it is an article. So is “Contacting Jared”, and so on down the line. The only exception is the Contact Form, and we’ll get to that later1.

I started transitioning my hardcoded content into articles by simply cutting and pasting each hardcoded title and its accompanying text from my page template and pasting them into a new article (Admin panel: content » write). Under the Section dropdown menu, I selected about so that each article would be assigned to the About section. Well that was easy.

Now I was at the mercy of Textpattern. As you see, I have 7 articles on that page and 1 Contact form. The Contact form is not an article, but rather a Textpattern form. As such, my dilemma was this: I could easily edit each article’s timestamp to force the articles to display in the correct order, but I wanted to insert the Contact form somewhere inbetween the end of the page (Why? I like to make things hard, that’s why). I didn’t want it to be the last item on the page. That being the case, using the standard <txp:article /> tag wasn’t going to work. That tag would simply output a list of articles assigned to the About section, allowing nothing to be easily inserted in the midst of those articles. My Contact form would have no choice but to end up either at the top or the bottom of the column.

I harrassed the fine folks at the Textpattern Forums, complaining ad nauseum about being unable to insert each individual article into a specific place on my page template. I wanted to be able to arrange the order of the articles regardless of date, section or category.

Rob came to my rescue (again) with a stunning tag: <txp:doArticle id="">. That’s right, id as in identification. Each time you create an article, it is assigned a number. You can see that number in the URL address of this very page. See? It’s 74. You can find out the article’s ID by going to your article list (Admin panel: content » articles) and rolling your mouse over the article titles.

The <txp:doArticle id=""> tag finally answered the question: How do I just plug in a single article anywhere I want? With this tag in my bag, I could now arrange my About section’s articles in any order I wished, as well as insert the Contact form inbetween any article on the page.

My hardcoded markup has now been replaced with this2:

<div id="center">
<h2>Name, Rank & Serial Number</h2>
<txp:doArticle id="67" form="static" />
<txp:doArticle id="68" form="static" />
<txp:doArticle id="69" form="static" />
<txp:doArticle id="70" form="static" />
<txp:doArticle id="71" form="static" />
<txp:doArticle id="72" form="static" />
<txp:article form="contact_form" limit="1" />
<txp:doArticle id="73" form="static" />
</div>

And there you have it. The page’s content is now stored in easily editable articles, and the order of the articles can be easily rearranged. It’s the perfect solution for my “static” pages, since
<txp:doArticle> is a tag I can use numerous times on the same page, and even transition sidebar content into articles.

i ain’t much of th’ teachin’ kind, but I hope this little discovery of mine helps others out in the way it helped me. Textpattern rocks.

Appendix

1 The Contact form is not an article because articles are automatically wrapped in <p> tags, thus invalidating the page. Instead, I created a form (Admin panel: presentation » forms) called contact_form and pasted my Contact form’s HTML right into the form. I then inserted the block of HTML into the About page template with <txp:article form="contact_form" limit="1" />. In this case, the form variable defines the content block and limit="1" makes sure the content block only appears once. 2 form="static" controls the way the article displays. By default, each article will display with a permalinked title and comments. I wanted to eliminate those two items, so I created form="static" as a new form (Admin panel: presentation » forms) and defined it like so: <h3><txp:title /></h3>
<txp:body />
<hr />

This form outputs a title with no permalink, the text body, and an <hr /> to divide the article entries.

Update, 8.19.05 – Please note that with the release of Textpattern 4.0, the <txp:doArticle /> tag has been removed. <txp:article /> will now accept the id attribute. So, <txp:doArticle id="67" form="static" /> should now be presented as <txp:article id="67" form="static" />.

Commentary


Pierce » 4593 days ago #

I don’t use Textpattern on my own site (no journal), but I use it for a few others I’ve designed. I always hardcoded static pages. Actually, until recently, I didn’t even include my static pages as pages in Txp at all, I just linked to outside the system. Got my head around it eventually. Reading this, I might even have a go integrating the whole thing. It don’ look so hard.

Addison Hall » 4593 days ago #

Holy crap! Where did txp:doArticle come from? It’s not a plug-in, right? This is very good to know…

Keep ‘em coming.

Jared » 4592 days ago #

No, it’s not a plugin. I didn’t even know it existed until I started making noise about it on the forums. It’s not documented anywhere else that I know of.

D. » 4592 days ago #

Is textpattern better than movabletype.org ?

Joshua Rivera » 4592 days ago #

Nice work jared, it looks really good.

Tim » 4592 days ago #

Jared, thank you for this article, i will use this for future reference for using the “doArticle”. I am new to TXP so this article really helps. Good work!

Andrew » 4591 days ago #

very clever.

Abel Rios » 4591 days ago #

You’d be surprised at the tons of goodies that TxP has. As soon as I “complete” my migration over to TxP, I’ll post on some of them as well. I even wrote an AdSense Plugin for multiple authors, and it works nicely.

Jared » 4591 days ago #

Awesome, Abel. There are some worthy efforts being made in the TXP community to document the software, but for now I think the most helpful stuff I run across are little “discoveries” made by regular folks.

AdSense for multiple authors? I’ll be interested to see the writeup on that!

D. wrote: Is textpattern better than movabletype.org?

Not necessarily better, just different. And MUCH lighter and dynamic.

Pierce » 4591 days ago #

Jared, I think you mean “dynamicer”.

Abel Rios » 4590 days ago #

Yeah, the guys over at TxP are working extra hard on all that stuff. It’s such a great tool, and the community can only make it better.

Is textpattern better than movabletype.org?

I’ll agree with Jared here. The install as rather simple as well, and who would’ve thought you would only upload just a few files (as opposed to Moveable Type’s 50+ files)?

MT and TxP are different in their own sense. Both are great, but are meant to do different things.

Travis Schmeisser » 4589 days ago #

Thanks dude! I just got most of my site switched over thanks to your article. How do you get the code Textpattern puts out to be formatted so evenly? I keep getting odd breaks in the code it outputs – example here (sorry – tried, but couldn’t get the @ code block to work). The unordered list for instance is what it keeps doing. What’s going on with that?

Alan » 4588 days ago #

Way cool! I had never seen the doArticle tag before. Thanks for this writeup.

Ray » 4588 days ago #

I know I’m a little late to the game, but this “new” tag is just the right thing for static pages! Thanks for sharing the knowledge, Jared. I’m designing a new website for a friend here at work and was wondering about how to do the about page. I didn’t want to hardcode it like I did my own, so I knew I’d be putting her info into articles. My only solution (before now) was to make sure that the info farther down the page got written first—essentially writing the page backwards. But this great little tag is perfect. A much better solution. I’m discovering Rob’s site is a great place to go for TxP info. I’m using his rss_suparchive plugin on my friend’s site as well.

Michael Bester » 4587 days ago #

This is great, Jared. It has opened up a lot of possibilities that I thought would be a lot trickier. Thanks for sharing…

Jeff » 4586 days ago #

Kudos Jared. You just made my life a lot easier. Kudos as well to those that pointed you in the right direction.

ferenczi » 4574 days ago #

you rock.

thanks for being so generous with your knowledge and experience.

f

David » 4530 days ago #

Jared – Textpattern and I were about to part company until I found your article on a desperate Google search. I had scoured the forum wondering why such a simple thing as placing articles on a page was so elusive. Please keep the advice coming.
D

« Older writing is available in the Archives.