I am using wordpress, and I am creating a “widget chooser” for every page of the site. On the backend of each page, I have 15 checkboxes – if the user chooses a checkbox, it shows that particular widget in the sidebar of that page.
I have a large PHP document, with 15 includes. Each include is a widget. If the user checks a box on that page, that include is triggered like so:
if( in_array( 'Blog', get_field('modules') ) ) {
include 'modules/blog.php';
}
This works great! But, there is no way for the user to specify the order in which the widgets will appear. I need to develop some sort of system that will allow the user to choose the order of the modules.
Heres what I was thinking- If I can get each checkbox to spit out a specified order, I would need some sort of way within php to reposition the includes:
if( in_array( 'Blog', get_field('modules') ) ) {
$order = 2;
include 'modules/blog.php';
}
if( in_array( 'Gallery', get_field('modules') ) ) {
$order = 1;
include 'modules/gallery.php';
}
Now I would need some way to reorder these two “blocks” based on their supplied order. Can I make that happen somehow? Obviously I want to use PHP, but if not possible I could do it with jQuery. Any thoughts?
Instead of including the modules, push the list to an array which will include them in the end. Like: