WordPress.org

Ready to get started?Download WordPress

Forums

Multiple instances of a single widget (8 posts)

  1. pasber
    Member
    Posted 6 years ago #

    Hello guys!

    I searched the forums, the developer stuff (codex etc), and even tried to find a plugin doing the following (to copy some code >_>), too:

    How do I have multiple instances of a single widget?

    I need this for my plugin pb-embedFlash to display multiple widgets with different flash content. At the moment, I'm using a workaround by putting the wp_register_... stuff into a for-loop.
    (Yes, I should use the register_... without wp_, but I don't find a documentation...) But it only works on Firefox, not on Internet Explorer... (don't ask me why...)

    Defining/forcing the number of widgets by copying the register_-functions x times is no solution for me.

    From Plugins/WordPress_Widgets_Api:

    Widgets - One or many

    Widgets can be coded so that they can exist one time or they can exist multiple times. WordPress is doing the work for you to instantiate your Widget multiple times if you follow some rules.

    But there is neither no link, nor an example...

    Overall, there are only little information on writing widgets...

    Maybe you can help me.

    - Pascal

  2. Justin Tadlock
    Member
    Posted 6 years ago #

    There is little information on this. What I done to make "multi-widgets" was look at the widgets file in WordPress:
    /wp-includes/widgets.php

    There's a section near the bottom that gives an example widget. It's labeled like this in the file:

    /* Pattern for multi-widget (allows multiple instances such as the text widget).

    I spent hours and hours trying to make these things, hacking bits and pieces together.

  3. deuced
    Member
    Posted 6 years ago #

    Well i saw it yesterday and havent read it all but i think it's an interesting tutorial that may help...

    http://wp.gdragon.info/2008/07/06/create-multi-instances-widget/

  4. pasber
    Member
    Posted 6 years ago #

    Many thanks for your answers! I'll play around with the code in widgets.php and read the tutorial!

  5. pasber
    Member
    Posted 6 years ago #

    Ok, I now found that my code wasn't that bad but the Internet Explorer is. Or the examples - whatever.

    Even the text widget, category widget and the RSS widget (which are also "multi-widgets") do not work properly on IE7 and have the same problems as my widget...

    Is this a common misbehavior or just on my installation?
    1. After adding a multi-widget to the sidebar, I first have to save the page/sidebar and then edit the widget. (Editing first does not work as of the widget disappears then...).
    2. When the paged is reload after updating, I can change and save every widget without problems.
    3. Normal widgets (searchbar, tags, etc.) work fine...

    As far as this is an Javascript issue, I would say I cannot fix it on my own. :/

  6. Milan Petrovic
    Member
    Posted 6 years ago #

    There are a lot of strange things happening with IE and WordPress, and I am not sure if the WordPress developers are going to fix them, because this strange things are not critical to WordPress working properly. This particular problem you had with multi widgets saving I didn;t noticed. But this could be related to a version of IE7. I have fully patched latest version of IE7 (last updated few days ago), and I can edit widgets before saving them for the first time.

    I have written the article Deuced has referenced before (thanx for that), and I have tested extensivlly code with different browsers, and I had no problems (with excpetion of IE6). I had made a lot of changes to the default example from 'widgets.php' and you can try if the example I made have the same problem. IE6 was a different story, and there is no way to make it work with multiple widgets before you save them first. So, if you follow both my article and widget.php example you will make multi widget that will work as it should in most of the browsers, not much else you can do to fix IE, this browser is beyond hope to ever be something worth using.

  7. pasber
    Member
    Posted 6 years ago #

    Thanks for your answer. I'll take a closer look to your code when I find some free time the next days/weeks :D.

  8. pasber
    Member
    Posted 6 years ago #

    After reading your article carefully: I'm using very similar code to initiate widgets. :)

    So it really seems to be the browser (IE 7.0.5730.11) causing the problems. As of there are only a few people (two until today) reporting such an issue (plus me), I think it's not worth taking another closer look at it.

    Many thanks for spending your time helping me!

Topic Closed

This topic has been closed to new replies.

About this Topic