WordPress.org

Ready to get started?Download WordPress

Forums

Widgets on Pages
Improvement: adding hooks to customize before / after_title tags (3 posts)

  1. leoloso
    Member
    Posted 1 year ago #

    Hi Todd,

    I added an improvement to your plugin, I hope you'd like to integrate it back into your plugin.

    I added some hooks to override the html tags. I think it is important since the widgets in the homepage or as a sidebar have a different format.

    My changes are preceded by comment // Hack

    function reg_wop_sidebar() {
      $options = get_option('wop_options_field');
      $num_sidebars = $options["num_of_wop_sidebars"] + 1;
      // register the main sidebar
      if ( function_exists('register_sidebar') )
        if ($options['wop_name_1'] != "") :
          $name = $options['wop_name_1'];
          $sidebar_id = ' id="' .$name . '"';
        else :
          $name = 'Widgets on Pages 1';
          $sidebar_id = "";
        endif;
        $id = 'wop-1';
        //$sidebar_id = 'wop-1';
        $desc = '#1 Widgets on Pages sidebar.
                Use shortcode
                "[widgets_on_pages' . $sidebar_id .']"';
    
    // Hack: add filter to modify the widget
    $default_args = array (	'before_widget' => '<li id="%1$s" class="widget %2$s">',
    						'after_widget' => '</li>',
    						'before_title' => '<h2 class="widgettitle">',
    						'after_title' => '</h2>'
    					);
    $sidebar_args = apply_filters("wop_widgets_on_pages_sidebar_args", array());
    
    // Parse together the plugin default args with the hook default ones
    $sidebar_default_args = wp_parse_args($sidebar_args['default'], $default_args);
    
    // In addition, parse together with sidebar specific args
    $sidebar_1_args = wp_parse_args($sidebar_args[$id], $sidebar_default_args);
    
    register_sidebar(array(
      'name' => __( $name, 'wop' ),
      'id' => $id ,
      'description' => __( $desc, 'wop' ),
      'before_widget' => $sidebar_1_args['before_widget'],
      'after_widget' => $sidebar_1_args['after_widget'],
      'before_title' => $sidebar_1_args['before_title'],
      'after_title' => $sidebar_1_args['after_title']
      ));
    // Hack: below is the original
    /*
    register_sidebar(array(
      'name' => __( $name, 'wop' ),
      'id' => $id ,
      'description' => __( $desc, 'wop' ),
      'before_widget' => '<li id="%1$s" class="widget %2$s">',
      'after_widget' => '</li>',
      'before_title' => '<h2 class="widgettitle">',
      'after_title' => '</h2>',
      ));
     */
    
      // register any other additional sidebars
      if ($num_sidebars > 1)  :
        for ( $sidebar = 2; $sidebar <= $num_sidebars; $sidebar++){
          if ( function_exists('register_sidebar') )
              $option_id = 'wop_name_' . $sidebar;
              if ($options[$option_id] != "") :
                $name = $options[$option_id];
                $sidebar_id = ' id="' . $name . '"';
              else :
                $name = 'Widgets on Pages ' . $sidebar;
                $sidebar_id = ' id=' . $sidebar;
              endif;
              //$sidebar_id = 'wop-' . $sidebar;
              $id = 'wop-' . $sidebar;
              $desc = '#' . $sidebar . 'Widgets on Pages sidebar.
                  Use shortcode
                  "[widgets_on_pages' . $sidebar_id .']"';
    
    		$sidebar_n_args = wp_parse_args($sidebar_args[$id], $sidebar_default_args);
    
    		register_sidebar(array(
    		  'name' => __( $name, 'wop' ),
    		  'id' => $id ,
    		  'description' => __( $desc, 'wop' ),
    		  'before_widget' => $sidebar_n_args['before_widget'],
    		  'after_widget' => $sidebar_n_args['after_widget'],
    		  'before_title' => $sidebar_n_args['before_title'],
    		  'after_title' => $sidebar_n_args['after_title']
    		  ));
    		// Hack: below is the original
    /*
      register_sidebar(array(
                  'name' => __( $name, 'wop' ),
                  'id' => $id ,
                  'description' => __( $desc, 'wop' ),
                  'before_widget' => '<li id="%1$s" class="widget %2$s">',
                  'after_widget' => '</li>',
                  'before_title' => '<h2 class="widgettitle">',
                  'after_title' => '</h2>',
          ));
    */
        }
      endif;
    }

    Cheers,
    Leo

    http://wordpress.org/extend/plugins/widgets-on-pages/

  2. toddhalfpenny
    Member
    Plugin Author

    Posted 1 year ago #

    Hey Leo,

    This is ace... thanks for the code; I shall certainly be including this (and crediting you of course) in the next release.

    Ta,
    Todd

  3. leoloso
    Member
    Posted 1 year ago #

    :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.