Common “How Do I?” questions [todo]
Here are some quick answers to common “How Do I?” questions.
How Do I..
…display something only on an individual article page?
Surround it with an txp:if_individual_article tag:
…display something only on list (section/front) pages?
Surround it with an txp:if_article_list tag:
…make an “About” page?
…make a reusable sidebar, header or footer?
With the txp:output_form tag.
…show a list of recent articles or comments in a sidebar?
For more control over a list of recent articles, use txp:article_custom instead.
FAQ: “How do I change the output of txp:recent_articles?”:https://textpattern.com/faq/26/change-the-output-of-txp%3Arecent_articles
…show a short list of articles or article links in a sidebar?
For simple lists, the recent_articles tag might do what you want (see above).
To list articles from a specific section or category, use the txp:article_custom tag. Create an article form containing only the tags you want, for example:
Then use a tag like
in your sidebar.
…show a short version of articles with a “read more..” link?
Use something like this in your article form:
read more.. <!-- full article body --> <txp:body /> </txp:if_article_list>
Excerpts automatically generated from the article body are possible through plugins.
…break an article list into columns, or insert ads between certain articles in a list?
pageby attributes of txp:article:
Textpattern CMS support forum: txp:article pageby attribute
…supply a special layout to the first article on a page?
Use the txp:if_first_article tag in your article form:
…apply a special layout to articles from a particular section when shown on the front page?
Use the txp:if_article_section tag in your article form:
<div class="linklog"></div> <!-- all other sections --> <txp:title /> <txp:body /> </txp:if_article_section>
…apply a special layout to articles from a particular category?
Use the txp:if_article_category tag in your article form:
<div class="linklog"></div> <!-- all other categories --> <txp:title /> <txp:body /> </txp:if_article_category>
…show a unique intro paragraph on each section page?
Post a “Sticky” article in each section containing the paragraph for that section, and display it with a
…show the same intro paragraph on more than one section page?
Post a “Sticky” article containing the text, and display it with the tag
123 is the ID number of the sticky article. Enclose it with the
tag if necessary.
…show a unique banner image or similar on a particular section page?
If the page layout for each section is to be identical except for a small element, you should probably share the same page template between all sections, and use the txp:if_section tag to selectively display variations:
…add a stylesheet for printing?
Create a new style named “print”, and add this to the
<head> portion of your page template:
…display a random article, or a link to a random article?
Put this in your page template:
…and create an article form named “random” containing the appropriate “article tags” txp:Category:Article_Tags, e.g:
…display articles in a different order?
To sort by title in ascending alphabetical order:
To sort by Category 1 in descending order:
To sort by Category 1 first, then article date:
To sort by a custom field1:
…display “Top Stories” first, then regular articles?
Use a custom field to identify your top stories, and use this tag in your page template:
Storing numbers in custom field 5 will bring articles to the top, with higher numbers shown first.
1 You must use the custom_n name here, not the custom field name as defined in Advanced Preferences.