2010-01-03 32 views
0

我正在制作我的第一个Wordpress小部件 - 只是一个加载在jQuery鸣叫如何获得一个Wordpress小部件来“记住”值

所以我的问题是,管理器屏幕上的小部件编辑器不会“记住”我的值,我敢肯定它只是与变量没有传递到_control函数有关。

那么有人会有什么建议吗?

这里是我的代码:

function widget_qTweet($args) { 
    extract($args); 
    $options = get_option('widget_qTweet'); 
    $title = empty($options['title']) ? 'Tweet, Tweet!' : $options['title']; 
    $total = empty($options['total']) ? '3' : $options['total']; 
    $username = empty($options['username']) ? 'kylehotchkiss' : $options['username']; 

    // Here's our "Tweet" 
    echo $before_widget; 
    echo $before_title . $title . $after_title; ?> 
    <script type="text/javascript"> 
    jQuery(document).ready(function($) { 
    $(".tweets").tweet({ 
    username:"<?php echo $username; ?>", 
    count: <?php echo $total; ?>, 
    loading_text:"Loading Tweets..." 
    }); 
    }); 
    </script> 
    <div class="tweets"></div> 
    <?php echo $after_widget; 
} 

function widget_qTweet_control() { 
    $options = get_option('widget_qTweet'); 
    if ($_POST['qTweet-submit']) { 
    $newoptions['title'] = strip_tags(stripslashes($_POST['qTweet-title'])); 
    $newoptions['total'] = strip_tags(stripslashes($_POST['qTweet-total'])); 
    $newoptions['username'] = strip_tags(stripslashes($_POST['qTweet-username'])); 
    } 

    if ($options != $newoptions) { 
    $options = $newoptions; 
    update_option('widget_qTweet', $options); 
    } 

    $title = htmlspecialchars($options['title'], ENT_QUOTES); 
    $total = htmlspecialchars($options['total'], ENT_QUOTES); 
    $username = htmlspecialchars($options['username'], ENT_QUOTES); 
    ?> 
<div> 
<p> 
    <label for="qTweet-title" style="display:block;">Widget Title:</label> 
    <input type="text" id="qTweet-title" name="qTweet-title" value="<?php echo $title; ?>" /> 
</p> 
<p> 
    <label for="qTweet-username" style="display:block;">Your Twitter Username:</label> 
    <input type="text" id="qTweet-username" name="qTweet-username" value="<?php echo $username; ?>" /> 
</p> 
<p> 
    <label for="qTweet-total" style="display:block;">Number of Tweets:</label> 
    <select id="qTweet-total" name="qTweet-total"> 
    <option value="1">1</option> 
    <option value="2">2</option> 
    <option value="3">3</option> 
    <option value="4">4</option> 
    <option value="5">5</option> 
    </select> 
</p> 
<input type="hidden" name="qTweet-submit" id="qTweet-submit" value="1" /> 
</div> 
    <?php 
} 
WordPress版本您使用的这些

回答

0

...如果它的2.8或更高版本的话,我会强烈建议使用新的WordPress的插件API ...这是一个面向对象的API很容易的工作,肯定会解决你的问题....

结帐: New Widget API

相关问题