Support » Everything else WordPress » How to customize Widget

  • Hi,

    I am creating a simple custom Twitter widget for my WordPress theme and am wanting to have it function so that I can access the widget from the WP admin -> appearance -> widgets area.

    It is almost working correctly except for the link, (this is added from the widget admin panel), which when clicked on, refreshes the page instead of taking me to my Twitter page.

    I have included the code below:

    function twitterWidget()
    	$settings = get_option("widget_twitterwidget");
    	$title = $settings['title'];
    	$twiturl = $settings['twiturl'];
            	<span class="subscribe" style="float:none;">
            	<img src="<?php echo bloginfo('template_directory')."/images/twitter-trans.png"; ?>" height="16" width="16" alt=""/>&nbsp;<a href="<?php echo "$twit_url"; ?>"><?php echo $title; ?></a>
    // Twitter Widget
    function twitterWidgetAdmin() {
    	$settings = get_option("widget_twitterwidget");
    	// check if anything's been sent
    	if (isset($_POST['update_twitter'])) {
    		$settings['title'] = strip_tags(stripslashes($_POST['twitter_title']));
            $settings['twiturl'] = strip_tags(stripslashes($_POST['twitter_twiturl']));
    	echo '<p>
    			<label for="twitter_title">Title:
    			<input id="twitter_title" name="twitter_title" type="text" class="widefat" value="'.$settings['title'].'" /></label></p>';
    	echo '<p>
    			<label for="twitter_twiturl">Twitter URL:
    			<input id="twitter_twiturl" name="twitter_twiturl" type="text" class="widefat" value="'.$settings['twiturl'].'" /></label></p>';
    	echo '<input type="hidden" id="update_twitter" name="update_twitter" value="1" />';
    register_sidebar_widget('Twitter', 'twitterWidget');
    register_widget_control('Twitter', 'twitterWidgetAdmin', 400, 200);

    Any suggestions on how I can get this to work correctly?


  • The topic ‘How to customize Widget’ is closed to new replies.