Parent and child pages in Textpattern
Oct 25, 12:53 PM in Content Management Systems
If you had an experince with WordPress, you noticed that WP pages can be easily built as a Parent and a Child. With some plugins Child pages can be displayed on the Parent one. It is definetly usful feature if you need to build a hierarchy of pages. Textpattern does not have such a feature, but it is possible to create a similar structure without extra plugins. Needless to say, one can use category, section and subsection hierarchy (there is a nice plugin adi_menu to enable subsections) but it is not easy to administer twenty or thirty sections, for example, or create a separate section for the sake of two child articles. So we will use just articles for this purpose.
- About – Parent article
- Services – Parent article
- service 1 – child article
- service 2 – child article
- service 3 – child article
- Contact – parent article
How do we connect two TXP articles as a Parent and a Child? The answer is through a category.
Unlike WP we can see article ID in the list of articles in Textpattern. So we need to create an article category and name it as our Parent article ID. For example 1, 2, 3, 4 whatever.
Child articles should be added to that category. In order to display the list of Child articles under the Parent in the form Default (Presentation → Forms) under the body we add the following code:
<ul class="Parent-Articles"> <txp:article_custom section="your-section" limit="999"> <li><txp:permlink><txp:title /></txp:permlink></li> <!-- list of parent articles -- > <ul class="Child-Articles"><!-- list of child articles if category name is the same as parent artilce's ID. If not, nothing will be displayed -- > <txp:article_custom category='<txp:article_id' limit="999"> <li><txp:permlink><txp:title /></txp:permlink></li> </txp:article_custom> </ul> </txp:article_custom> </ul>
Thus you will get all Child articles of the Parent.
The breadcrumbs is very importants site element for usability and SEO. It helps both robots and humans crawl the site faster. The second question is how to build these breadcrumbs in connection with Parent & Child Page Hierarchy. By using this code:
<txp:if_individual_article> <!-- On the individual article page standart TXP breadcrumbs will be displayed --> <txp:breadcrumb label="Home" link="1" separator="»" title="1" /> <!-- TXP breadcrumbs displaying Homepage -> Section --> <txp:if_article_category> <!-- If article added to category named as Parent Id, the category articles will be displayed. <txp:if_article_category /> used twice to enable another hierarchy level if needed. --> <txp:article_custom id='<txp:category1 />'> <txp:if_article_category> <txp:article_custom id='<txp:category1 />'> » <txp:permlink><span><txp:title /></span></txp:permlink> </txp:article_custom> </txp:if_article_category> » <txp:permlink><span><txp:title /></span></txp:permlink> </txp:article_custom> </txp:if_article_category> <txp:else /> <txp:breadcrumb label="Home" link="1" separator=" » " title="1" /> <!-- for article list pages displaying Homepage -> Section > </txp:if_individual_article>
This way one can easily build Parent & Child Page Hierarchy without any plugins in CMS Textpattern.