WordPress.org

Forums

Starting with widgets: Hello World doesn't work (10 posts)

  1. clarke1866
    Member
    Posted 10 years ago #

    Hi,

    I have taken the widgets documentation and created a widget based on the instructions. I simply cut and pasted the hello world example off the page and into a file (adding the proper php code start and endings) and nothing happens. No widget show s up in the admin nor in the sidebar. What am I doing wrong? Here is the code:

    <?php
    function widget_1($args) {
    extract($args);
    ?>
    <?php echo $before_widget; ?>
    <?php echo $before_title . 'My Unique Widget' . $after_title; ?>
    Hello, World!
    <?php echo $after_widget; ?>
    <?php
    }
    register_sidebar_widget('My Unique Widget', 'widget_1');
    ?>

  2. TechGnome
    Moderator
    Posted 10 years ago #

    did you install the widgets code (not your widgets but the widgets engine itself)?

    -tg

  3. clarke1866
    Member
    Posted 10 years ago #

    Thanks for your reply. Yes, other widgets work fine as the widgets plugin is installed. I'm sure its something very minor that I'm missing.

  4. clarke1866
    Member
    Posted 10 years ago #

    Anyone have any thoughts?

  5. Kafkaesqui

    Posted 10 years ago #

    A couple.

    1. Widgets are in fact just plugin files. Have you set up your test widget as a plugin?

    2. I don't feel the example material covers enough. I'd suggest looking over the Google and Del.icio.us widget plugins for the best representation of what's required here.

  6. clarke1866
    Member
    Posted 10 years ago #

    I will look over those plugins carefully. I guess I just thought that the hello world example would echo 'hello world'. Both the google and delicious plugins do a lot, but a simple example is nice too. Thanks for your reply, I appreciate it.

  7. Kafkaesqui

    Posted 10 years ago #

    I agree on the 'simple' example. There's nothing like a Hello Dolly sort of plugin to help one understand the basics, and the same goes for widgets.

  8. Kafkaesqui

    Posted 10 years ago #

    OK, because I'm a giver...

    My Widget - example sidebar widget plugin:
    download widget | view source

    It's even useful as is!

  9. apidevlab
    Member
    Posted 10 years ago #

    @Kafkaesqui

    Excellent m8 very useful thanks for taking the time

  10. clarke1866
    Member
    Posted 10 years ago #

    Kafkaesqui, thank you for your generosity for sharing the above code. I appreciate it very much.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags