widget coding issue
-
I’m trying to learn how to create widgets and I have 2 questions:
first… where can I put my sidebar widget file so that wordpress will load them. I’d like to keep the widget code out of the function file. I tried putting it in it’s own file under wp-content/plugins/widget-name/widget-name.php but that did not work. I would like to make it available to “all” my themes so I did not want to put it in a widget folder under a specific theme theme-name/widgets/widget-name.php as I had read was possible. Is there somewhere I can place my widget-name.php file top make it available to all of my themes?Second question is a frustrating coding issue. Could anyone tells me why the following code:
<blockquote>function form($instance){ ?> <p> <label for="<?php echo $this->get_field_id('title'); ?>"> <?php _e('Title:'); ?></label> <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" /> </p> <?php }</blockquote>
gives me a “Notice: Undefined index: title” in my widget input box when I first place it in the side bar. but the following code does not:
<blockquote>function form($instance) { echo '<p>'; echo '<label for="' . $this->get_field_id("title") .'">Random Trivia:</label>'; echo '<input type="text"'; echo 'name="' . $this->get_field_name("title") . '" '; echo 'id="' . $this->get_field_id("title") . '" '; echo 'value="' . $instance["title"] . '" />'; echo '</p>'; }</blockquote>
(they seem nearly identical to me)?
Thanks for any help
- The topic ‘widget coding issue’ is closed to new replies.