Dynamic content in a widget

I have to make a widget from where the user will be able to add a few images and then I will show only some of them, randomly, and it will be automatically changed on page refresh. The problem is that the number of images is not known, it may be 2, it may be 5. I was thinking of using an “add more” jQuery button but I have problems with working on data from an array.

Has somebody done something like this before? If you have another idea about doing this, I’d be glad to hear of it.

Note: If you have knowledge about a widget which uses this kind of function do not hesitate to tell me, maybe I can get inspiration from there.

2 Answers
2

I have a little to none experience in developing a plugin or widgets, but I believe this is certainly doable in a custom WordPress theme.

  1. Output an ajax multiple file upload form in the sidebar. Link
  2. Handle the file uploads and save them as attachment. Link
  3. After you get the attachment(s) ID, save them as an array in the user’s meta e.g ‘sidebar_image’. Codex
  4. Back to the sidebar, check if current user already have the ‘sidebar_image’ meta.
  5. If she does have a value, then just create a attachment query, according to the meta value. Codex

If you want this method as a widget. The function on step 2 and 3 will be the same if you use a proper ajax method.

Hope this help.

Leave a Comment