Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-09-21 15:51:42

radneck
Plugin Author
Registered: 2005-07-03
Posts: 109

esq_sectionsort - Custom sorting of sections

esq_sectionsort

Custom sorting of sections and categories using a drag and drop interface.

v2.0.5 – GitHub Repo: github.com/jools-r/esq_sectionsort

Textpattern 4.8.0+ required.

Previous versions:

v2.0.2b – 2014-12-04 – textpattern.org download of Uli’s modifications for Textpattern 4.6.0+
v2.0.2 – 2014-12-04 – textpattern.org download. Textpattern 4.5.0+

Thanks to rsilletti, maverick, jagorny and anteante for bug reports/fixes.

  1. Install and activate the plugin
  2. Go to Presentation > Sections or Content > Categories
  3. There should be an a new sort indicator next to every section (except for default) and category – use this to drag and reorder sections and categories (categories are restricted to reordering within their current parent)
  4. In your Pages and Forms, wherever you want to sort by your new custom order, add sort="sectionsort" or sort="categorysort" (or sort="sectionsort desc" / sort="categorysort desc" if you want it in reverse order) to the <txp:section_list> and <txp:category_list> tags (respectively).
  5. ???
  6. PROFIT!!!

I have had the requirement to custom sort sections in several previous Textpattern sites, and have resorted to hacks to do so. With the new pluggable_ui() and plugin lifecycle management available to plugin developers in TXP 4.2.0 this can now be done with a plugin, so I thought why not? Also, I have seen this asked for before, so hopefully a few people may find it helpful.

Update:

After being contacted by a few members of the community for a version of this plugin that allows sorting of categories as well as sections, I decided to add this functionality in. Jakob provided me with his version of the category sorting code, and I’ve merged it into the original plugin and updated it slightly for the latest version of Textpattern. Kevin suggested the drag and drop interface.

Note:

This plugin modifies certain admin pages, and relies on particular markup hooks to work properly. I have only tested the plugin on the default admin theme. It will probably work fine with most other admin themes, but this hasn’t been tested. Please report any issues you may find.

To avoid changing any core Textpattern code, the sort data is stored and retrieved using JavaScript, which means you will need JavaScript enabled when updating these fields, which shouldn’t be a problem as most of the backend requires JS. JS is not required when outputting the <txp:section_list> / <txp:category_list> on your site however, everything is handled by Textpattern server-side.

This plugin does modify the database, but you can revert the changes by going into the plugin options.

This is my first publicly released plugin, so please provide feedback if you have any – especially if you encounter errors.

Last edited by radneck (2015-11-04 07:34:23)

Offline

#2 2010-09-21 16:39:15

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: esq_sectionsort - Custom sorting of sections

You’re a plugin author now and I’ve added your plugin prefix to the reserved list.

Offline

#3 2010-09-21 16:41:58

radneck
Plugin Author
Registered: 2005-07-03
Posts: 109

Re: esq_sectionsort - Custom sorting of sections

ruud wrote:

… added your plugin prefix to the reserved list.

Oh yeah forgot about that, thanks.

Offline

#4 2010-09-21 21:29:18

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: esq_sectionsort - Custom sorting of sections

Thanks, Mitch. Exactly what I need right now.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#5 2010-09-21 22:47:09

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: esq_sectionsort - Custom sorting of sections

The plugin as it stands is throwing an error and failing to install in the DB with this error:

Warning: Table ‘DEV.txp_section’ doesn’t exist SHOW COLUMNS FROM txp_section textpattern/lib/txplib_misc.php(594) : eval()’d code:130 getRows() in /Applications/MAMP/htdocs/TXP/textpattern/lib/txplib_db.php on line 85

Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/TXP/textpattern/lib/txplib_misc.php(594) : eval()’d code on line 131

It’s not set up for table prefixes, the following fix in esq_sectionsort_checkDB() works well.

function esq_sectionsort_checkDB() {
	$columns = getRows("SHOW COLUMNS FROM ".safe_pfx('txp_section')."");

Offline

#6 2010-09-22 02:59:52

radneck
Plugin Author
Registered: 2005-07-03
Posts: 109

Re: esq_sectionsort - Custom sorting of sections

uli wrote:

Thanks, Mitch. Exactly what I need right now.

No worries mate, let me know how it goes for you.

rsilletti write:

The plugin as it stands is throwing an error and failing to install in the DB […]
It’s not set up for table prefixes […]

Thanks Rick. I tried to use the the standard Textpattern DB wrappers as much as possible to handle table prefixes etc, but looks like I missed one. This has been fixed up now with the latest version – please try again and let me know how you go.

Last edited by radneck (2015-11-04 07:45:40)

Offline

#7 2010-09-22 11:37:59

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

Re: esq_sectionsort - Custom sorting of sections

Mitch

I had installed the first version, but not activated it yet. I tried installing the latest version and am getting:

“Warning: Duplicate column name ‘sectionsort’ alter table txp_section ADD `sectionsort` VARCHAR NOT NULL in /path/to/textpattern/textpattern/lib/txplib_db.php on line 85”

Can this be ignored or has the install of the updated version failed?

Offline

#8 2010-09-22 11:56:41

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: esq_sectionsort - Custom sorting of sections

maverick

I’m only getting that warning once. If you key through it, it clears and seems to operate fine from there. The installed column also is there as expected.

Last edited by rsilletti (2010-09-22 11:56:59)

Offline

#9 2010-09-22 12:29:11

radneck
Plugin Author
Registered: 2005-07-03
Posts: 109

Re: esq_sectionsort - Custom sorting of sections

Maverick- rsilletti is correct, you can safely ignore that one.
I have updated the code, so that the warning won’t come up again now – thanks for letting me know.

Last edited by radneck (2010-09-22 12:36:52)

Offline

#10 2010-09-22 15:35:13

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

Re: esq_sectionsort - Custom sorting of sections

thanks guys

Offline

#11 2010-11-27 03:23:32

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: esq_sectionsort - Custom sorting of sections

This is perfect. Exactly what I need. Except I need it for categories. Does anyone know of an equivalent?


Kevin
(graphicpush)

Offline

#12 2010-11-27 04:41:21

radneck
Plugin Author
Registered: 2005-07-03
Posts: 109

Re: esq_sectionsort - Custom sorting of sections

kevinpotts wrote:

This is perfect. Exactly what I need. Except I need it for categories. Does anyone know of an equivalent?

Hi Kevin,

The timing of your post is disturbingly coincidental; I just got an email from Jakob a day ago indicating he needed the same thing, and that he had adapted esq_sectionsort for categories, calling it esq_categorysort. He sent it to me for a bit for a tidy up before release, but it won’t be up for public download for a while as I’m pretty busy just now.

That being said, if you email me I’ll forward you the new plugin as it currently is (it works well, just needs a slight tidy up, and perhaps merging into the existing plugin).

Last edited by radneck (2015-11-04 07:42:20)

Offline

Board footer

Powered by FluxBB