The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Multiple widget without options (1 post)

  1. tkhobbes
    Posted 7 years ago #

    Hi all

    I am trying to get my head around the "multiple widgets" - i. e. widgets that can be used on more than 1 sidebar.
    The challenge in my case is low - the desired widget simply shall output some text. I know that I could simply use the text widget, but for reasons beyond simple explanation, I can't.

    Here's my code - it's in functions.php of my theme, can someone explain why it does not work (the widget is not appearing on the widgets page to select & add to sidebars)?

    class pictureMulti {
      function widget_myPicture($args, $widget_ars = 1) {
        if (is_numeric($widget_args))
          $widget_args = array('number' => $widget_args);
        $widget_args = wp_parse_args($widget_args, array('number' => -1));
        extract($widget_args, EXTR_SKIP);
        $options_all = get_option('widget_picture_multi');
        if (!isset($options_all[$number]))
        $options = $options_all[$number];
          <p>some text to be displayed here.</p>
      function pictureMulti() {
      function init() {
        if (!$options = get_option('widget_picture_multi'))
          $options = array();
        $widget_ops = array('classname' => 'widget_picture_multi', 'description' => 'Display Picture (Multi)');
        $name = 'Picture Multi';
        $registered = false;
        foreach (array_keys($options) as $o) {
          $id = "picturemulti-$o";
          $registered = true;
          wp_register_sidebar_widget($id, $name, array(&$this, 'widget'), $widget_ops, array('number' => $o));
        if ($registered) {
          wp_register_sidebar_widget('picturemulti-1', $name, array(&$this, 'widget'), $widget_ops, array('number' => -1));
    $pictureM = new pictureMulti();
    add_action('widgets_init', array($pictureM, 'init'));

    (Note: I was following this site: http://wp.gdragon.info/2008/07/06/create-multi-instances-widget/)

    Thanks, tkhobbes

Topic Closed

This topic has been closed to new replies.

About this Topic