Home | Warum | WordPress Widgets & Plugins

5. Mai, 2006

WordPress Widgets Hack: Show Title on Widget

wordpress widgets hack_ to show titleHaving a lot of RSS/Text or King Widgets brings up a Problem in the Admin Interface.

You have to klick on each Widget to see whats in there.

The Solution is to show the title of each Widget (if it has one) next to the widget name in the drag drop view. 

Code

I made a little change to the widget.php (the original widget plugin v.1.0).

 

Open widget.php and go to Line 607 -> in function widget_draggable($name)

Original Line 607
———– 

echo "<li class=’module’ id=’widgetprefix-$san_name’><span class=’handle’>$name$popper</span></li>"; 

———–
Replace the Line 607 with this:
———–

// start widget title enhancements by georg leciejewski
    if(!empty($registered_widgets[$name]['params'])){
        $number = $registered_widgets[$name]['params'][0];
        $options =get_option($registered_widgets[$name]['classname']);
        $widgettitle=$options[$number]['title'] ;
    }else{
        $options =get_option($registered_widgets[$name]['classname']);
        $widgettitle=$options['title'] ;
    }
    //show only if title is populated
    if(!empty($widgettitle)){
        $show_title= ‘<small>( ‘.$widgettitle.’ )</small>’;
    }
// end widget title enhancements by georg leciejewski
    echo "<li class=’module’ id=’widgetprefix-$san_name’><span class=’handle’>$name $show_title  $popper</span></li>";

———–

Now the Widget Title guides you the way through your widget jungle.

Verwandte Artikel:

7 Kommentare zu “WordPress Widgets Hack: Show Title on Widget”

  • 1.

    Great Hack. I’ve been thinking of suggesting this to the WordPress programmers. Please consider putting your code in as a case at the WordPress ‘bug’ site, http://trac.wordpress.org/

  • 2.

    thanks!
    i looked at the trac but that is only for wordpress not the widgets.

  • 3.

    $show_title= ‘( ‘.$widgettitle.’ )’;

    Need to change ‘ to “

  • 4.

    correction. that is the ones surrounding

  • 5.

    [...]  初期状態のwidgets.phpでは自分で設定したタイトルがウィジェットの各タブ?には表示されないので、ポップアップをクリックしないと確認できず、不便です。この問題をMP:Blog – Mediaprojekte – » WordPress Widgets Hack: Show Title on Widgetで解決してくれています。が、このままだと設定したタイトルとタブのタイトルが同じ場合でも表示されてしまい、見辛く(煩く)なってしまうので、変更しました。 [...]

  • 6.

    Thanks. For those using a more recent version of widgets.php, the new insertion point is at line 621. Also note that the code sample above contains “smart quotes” – you’ll need to correct them all to plain quotes.

  • 7.

    Thanks for pointing this out!