Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
15 posts Page 1 of 2
With Couch v2.x, this solution will no longer be required as it comes with this feature built-in. Please see the 'Manually reorder normal cloned pages' section at viewtopic.php?f=5&t=10241 for details.

Hi everybody :)

One big drawback of cloned-pages, as they exist as of v1.4.5, is that we cannot easily reorder them manually from the admin-panel (like what we can do with 'nested-pages').

Pages always appear in the descending order of their publish-dates and tweaking the publish-dates by editing each page, so as to reorder them, is too tedious to be considered practical.

To work around this limitation, some time back I coded up a quick-n-dirty solution that involves the use of 'custom admin-screens' (http://docs.couchcms.com/concepts/datab ... in-screens).

I think it could be useful to others so I am sharing it here.
N.B. Please treat this as a 'band-aid' fix for the current version (i.e. 1.4.5). The next version will have this functionality built in so this is just an interim measure.

In the attached zip, you'll find three files.
1. Please place the 'manual_sort.php' in 'couch/addons' folder.
2. Place the other two files (i.e. 'manual_sort.html' and 'manual_sort_inner.html') within the snippets folder of your installation - this location by default is 'couch/snippets' but can be changed from the config file. So please make sure to place the files in the correct folder).

With the files in place, suppose you wish to make a template named 'contacts.php' manually re-orderable, edit couch/addons/kfunctions.php (if this file is not present you'll have to rename the kfunctions.example.php to kfunctions.php) and add to it the following line -
Code: Select all
$FUNCS->register_admin_listview( 'contacts.php', 'manual_sort.html' );

And that is it. Coming back to the admin-panel you should find that you are able to manually reorder normal cloned pages just like nested-pages.

For every template you wish to add this functionality, just add the same line of code in kfunctions.php (of course, changing the name of the template).

Hope this helps.

Attachments

Thx KK! Very helpfull!
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
Thanks for sharing this with us, KK. It's a welcome addition to the functionality of cloneable templates.

Implementing the addon created problems for me. I tried retrofitting it into an existing template. I installed and activated the addon as explained. I was able to move pages up and down in the list, and the changes were reflected on the front end.

But my list of pages was turned around: the last pages were at the beginning of the list, and when I tried to access list pages other than the first in the admin panel, I got the error "Corrupted Content Error - The page you are trying to view cannot be shown because an error in the data transmission was detected."

All of the pages displayed properly on the front end. Only the back end was disrupted. Deactivating the addon returned everything to the way it was before.

Is it not possible to retrofit the addon into an existing template, or is there something else going on?
Hi Tim,

But my list of pages was turned around: the last pages were at the beginning of the list,
That is because this addon, by default, uses 'asc' order instead of 'desc' that is used by blog type listing (where the latest page is shown first; here it gets added last instead). This is to match the behaviour of nested-pages but it can be changed if you wish.

However the second problem you mentioned bothers me -
when I tried to access list pages other than the first in the admin panel, I got the error "Corrupted Content Error - The page you are trying to view cannot be shown because an error in the data transmission was detected."
This is totally unexpected and should have nothing to do with the addon really.

Could you grant me access to your admin-panel please? Allow me to take a look at it.

Thanks.
Thanks for entrusting me with the creds, Tim.

I logged-in and found that your site was using a renamed index.php (start.php). This addon failed to take this situation into consideration and was trying to call index.php from the pagination buttons and ergo the problem.

I've rectified this and re-attached the modified zip above.

Please check and confirm (your site already has the modified files).

Thanks for all your help.
This addon failed to take this situation into consideration and was trying to call index.php from the pagination buttons...

That corrected it. I guess I might have spotted it if I had looked at the URL.

Just by way of feedback, I like the drag-and-drop method of repeatable regions better than the up and down arrows in this addon.

Thanks again. This is a nice enhancement for cloned templates.
Very welcome addon! Thanks a lot KK
I've found another bug...
Reorder a cloned template with unpublished posts inside, sorting a the published pages with an unpublished one, the published page becomes unpublished and vice versa.
Reorder a cloned template with unpublished posts inside, sorting a the published pages with an unpublished one, the published page becomes unpublished and vice versa
This addon works by swapping the publish-date of the two adjacent pages. Unpublished pages, incidentally, are pages with a publish-date of '0000-00-00 00:00:00'. Swapping the dates would thus result in swapping the publish-status too.

That said, I agree it should be treated as a bug.

As I mentioned earlier, this addon is just a stop-gap measure and the coming up version will have this feature natively built-in (and it won't use publish-date to change the sorting).

So please bear with this for a little while more :)
Does not work in CouchCMS 2.1. Can this be reflected in the original post?
15 posts Page 1 of 2