Textpattern tips, tutorials and code snippets

Sorting sections with a drag and drop interface

I recently came across stm_article_order, which uli has updated and which works nicely to allow clients (or yourself) to reorder articles with a simple drag-and-drop interface. This means you aren’t constrained to the various sort methods which, though they are extensive, won’t always get the job done.

I thought it would be nice to use this same interface for sorting sections. Though there are other plugins just for this purpose, the idea of having everything in one pane (mostly for clients’ sake) appealed to me.

The general process is:

  • Install the stm_article_order plugin
  • Create a section called “Section Order” or “Section Sort” or similar
  • For each section that you wish to include in a <txp:section_list />, create an article whose title matches that of the section name
  • To output a nav menu in the form of an unordered list of links, use <txp:section_list /> like so:
<txp:section_list sections='<txp:article_custom section="section-order" sort="position asc"><txp:article_url_title />,</txp:article_custom>' active_class="current" wraptag="ul" break="li" class="" />

Articles in section sort

Section sorting

Advantages and disadvantages

I often hand-code the main navigation for a site, but the advantage of using some kind of section sort is that a client can easily change the order of the sections in the nav menu, or potentially even add new sections, without much fuss. The advantage of using this method in particular is that you or your client can sort Sections using the same interface you use to sort Articles.

The main disadvantage I see is that if you want to allow a client to add new sections, this means they also have to add a matching new article. However, for most sites I don’t think adding new sections is something a client should undertake on their own anyway.

Use Textile help to style your comments