• ckdnz

    (@ckdnz)


    Hi,

    I am looking for some clarification on the correct way to code some aspects of WordPress widgets (not plugins), using the new 2.8 widget API as per below:

    class My_RSS_Widget extends WP_Widget {
    	function My_RSS_Widget() {
    		//Constructor
    	}
    
    	function widget($args, $instance) {
    		// prints the widget
    	}
    
    	function update($new_instance, $old_instance) {
    		//save the widget
    	}
    
    	function form($instance) {
    		//widgetform in backend
    	}
    }
    register_widget('My_RSS_Widget');

    1. When creating an image path within a widget for an icon I want to use the theme url or at least even the blog url, however the only method that seems to work for me so far is using the full path. For example:

    echo'<a href="'.$about_smfriendfeed.'" title="FriendFeed"><img src="http://www.myblog.com/temp/wp-content/themes/mytheme/includes/images/friendfeed.png" alt="Friendfeed" /></a>';

    I could previously achieve this by using code similar to this (see below):

    <img src="<?php echo bloginfo('template_directory')."/images/i18.png"; ?> " class="" title="" alt=""/>

    However this does not work with the new API.

    2. If the user does not select a particular option in the widget admin how can I ensure that that option does not display on the frontend? I thought it might be something like this:

    function form($instance) {
    		$instance = wp_parse_args( (array) $instance, array( 'friendfeed' => false, 'entry_title' => '', 'comments_title' => '' ) );

    But this does not seem to be correct.

    3. For multi instance widgets what code do I use so that the user does not have to re enter details for a second time.

    Any help would be greatly appreciated. Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator James Huff

    (@macmanx)

    The following document may help, but I have a feeling that you’ve already read it:

    http://codex.ww.wp.xz.cn/Widgets_API

    Thread Starter ckdnz

    (@ckdnz)

    Thank you. Yes, I have read the WordPress document and read most of the widget tutorials available. Currently though I have found no tutorials or examples that outline the methods that I posted above.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Creating a Widget Using the New 2.8 API’ is closed to new replies.