• Anyone know how to change the menu_order ID on an image?

    Basically I want to add a piece of code to allow users to re-order the images on a post, so I need to be able to re-write the menu_order ID for a specific image attached to a post.

    TIA.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hi there.
    You don’t need to (and would not be a very good idea to let your users) change the menu_order ID of your post images. Basically, that would imply making changes to the Database directly, and I really don’t think you should cross that line. Plus, it would not allow users to have their own customized order.
    What I suggest instead is a Javascript approach, mainly, using (jquery-ui sortable combined with either:
    1. jQuery cookie, so as to be able to store the image order of all your posts as a cookie on the user’s computer. The downfall of this being user choices would get deleted if they clear their browser cache; OR
    2. An AJAX call to a PHP file that would save users’s choices in a specially created field inside the wp_users table.
    I hope that was helpful.

    Thread Starter dibbit

    (@dibbit)

    Thanks for the reply. When I said “users” I did in fact mean users of the website not visitors. I need to allow a user to edit the order of images on their own page. Sorry that I didn’t make that clear.

    I don’t really want to make changes direct to the database, and was hoping that there is some function I can call to update the images?

    Ok, now you lost me completely. If your users are registered users, and what you want is to give them the flexibility of sorting the images in their posts and pages, why can’t they edit them and change the order of images themselves directly?

    Thread Starter dibbit

    (@dibbit)

    Indeed why can’t they? WordPress just isn’t flexible enough to do that, so I need a different solution, hence my question.

    Just to restate I need a user to be able to change the order of the images on one page and not be able to delete, upload or alter the order of images on any other pages.

    Actually, you can totally do that with WordPress. If you give your users the role of Authors, they will be able to edit their pages and posts butnot other users’. Editors, on the other hand, have the capability of editing others’ pages and posts. You should definitely check out Roles and Capabilities.
    If you need to customize your roles, you can use a plugin called Role Manager. It hasn’t been updated in a while, but I’m using it in all my sites and still works like a charm. If you would rather use a newer one, just search for “Roles”, “capabilities” or “Manager” in the Plugin Directory.
    Cheers!

    Thread Starter dibbit

    (@dibbit)

    Are you sure I can give them access to the media uploader without them then having access to the media library and hence other users images?

    Nope, I never said that. If they have access to the Media Library they will be able to see all images available, regardless of their Role, and use them in their posts, but they won’t be able to edit other users’s pages or posts.
    However, based on your original question, that should not be a problem.

    Thread Starter dibbit

    (@dibbit)

    No. If they can access the media library they can delete other users images.

    Back to the original question I suppose, but thanks for your suggestions.

    I’m sorry, but that was not your original question, and FYI, you will not find a solution involving the Media Gallery and User Roles because WP is designed so that media content is public to all users.
    You could try to use another Media Manager, but I don’t know any that would let you apply permissions to the uploaded media.
    Good luck.

    Thread Starter dibbit

    (@dibbit)

    That is why I am looking for an alternative to the media uploader. My original question remains:

    “Anyone know how to change the menu_order ID on an image?”

    If I knew how to do that I could write a bit of code to do what I want in half an hour or so.

    Thanks again for your suggestions.

    In that case, you could disable the Upload Files capability of your authors and use the tinymce image insertion button for inserting images into posts. Your users would only be able to insert images from an URL (i.e., uploading images won’t be available). I co-develop a pretty neat plugin that allows you to add/remove buttons from the tinymce editor called Ultimate TinyMCE, so you could add your button that way.
    You could also try a plugin like NextGEN gallery (NGG) to replace the disabled Media Library. I know NGG adds custom capabilities to roles, but I don’t know if users are allowed to edit / use media uploaded by others.

    Dibbit, there is a Media Order plugin which allows you to directly update the menu_order ID of an image. I wouldn’t recommend this approach, however, as the UX is pretty clunky.

    WordPress 3.5+ now has a great drag-and-drop interface for Gallery objects within the post editor. I have solved this problem myself by inserting a Gallery into a post, and then calling the_content() rather than using get_children() to get the attached images.

    There is one more step, however. WordPress adds a lot of extraneous styles to the Gallery by default. These are defined in the gallery_shortcode() function in wp-includes/media.php and can be overridden by adding a custom function to functions.php. I have based my function on this article, but I can provide more specifics if you’d like.

    With this approach, you can create multiple galleries using the same images without having to fundamentally change the menu_order ID for your images. Hope this helps!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How to change the menu_order ID on an image?’ is closed to new replies.