Although Textpattern is a very powerful content management system based on the concept that articles form the foundation of each site, it does not currently offer an out of the box method of manually sorting articles in numerical order.
Of course this can be done by changing the article publication dates, but this is counter-intuitive and a pain to update should you or your client want to change the order of articles in the future.
To make sorting articles manually very easy for you or your clients, we just need to install and activate the glz_custom_fields plugin:
Github repo for glz_custom_fields
Note: As of writing, 1.4.0-beta1
is the latest version and updated for TXP 4.5.x
.
Install the glz_custom_fields plugin
Once the plugin has been installed and activated, we can add a new custom field within which we will assign the numerical order for each article.
Be sure to read the install.md
file contained in the glz_custom_fields
download folder, particularly with regard to backing up your database first (important!) and creating a /plugins
folder at the root level where /textpattern
resides. After activation of the plugin, visit the “Options” page and check if anything needs to be changed.
Create a new custom field
Visit the “Extensions” tab in Textpattern Admin and click on “Custom Fields” if you have more than one extension activated.
Click on the first available custom field in the list or edit an existing custom field that you no longer need. Choose these settings:
- Name: Article_sort
- Type: Select
- Position: As you prefer – this setting determines the order of the custom fields in the Write tab
- Value: Each value must be on a separate line. I entered 1-50 but you should set the highest number based on how many articles you need to order in the given section
Click save and visit your Write tab. You should now see a select drop down with 1-50 (or whatever you entered) under “Custom fields” on the left side of the screen.
Sort your articles
The next step is to sort your articles from 1-50. Remember that for the articles to display correctly in the order that you choose, all of the articles within the section must have an order assigned – i.e 1, 2, 3, 4, etc.
Add a snippet to your article code
Within your page template or form, find the call to <txp:article />
or <txp:article_custom />
for the section that you want to sort manually.
Example:
<txp:article sort="custom_2+0">
<div class="title">
<h3><txp:title /></h3>
</div>
<div class="content">
<txp:body />
</div>
</txp:article>
Note: Adjust the sort="custom_2+0"
to reflect the custom field set number that you chose earlier. To find the number, go back to Extensions > Custom Fields and click “edit” next to the Article_sort
custom field. Above the “Name” attribute you should see “Edit custom_2_set” or similar. That is the number referenced in the code above.
More details on sorting for articles may be found in the Wiki entry or in Custom article groups in Textpattern.
Small issue with link_to_next and link_to_prev
While the above method is perfect for clients who want to be able to sort their articles easily, at the time of writing this method does not work with the link_to_next
and link_to_prev
tags. More info in this thread.