2011-11-28 57 views
2

是否可以從WordPress側欄發佈發佈請求?如何從WordPress側欄發佈發佈請求?

我想打開頁面,這需要一些參數發送POST請求。但我發現在側邊欄的文本小部件中不允許使用FORM標記,也不允許使用JAVASCRIPTONCLICK語法。

這是否有任何方法來實現這一目標?

感謝

更新1

我在WordPress的免費賬號。

回答

1

您是否希望避免編輯模板代碼?

如果沒有,那麼你應該能夠從你的Wordpress主題目錄打開sidebar.php,並直接在那裏。

+0

我應該能夠做到如果我在wordpress.com上有最簡單的帳戶,這是什麼? – Dims

+0

啊,你應該在原來的問題中指定那個! –

+0

對不起,我是wordpress新手,並不認爲它很重要! – Dims

1

您可能需要爲此創建自己的插件和小部件。您可以在窗口小部件中輸出表單和輸入標籤。

在下面的示例中,您可以在「小部件」函數中輸出表單。例如,你可以在你的插件創建一個目錄目錄,並將它命名,然後創建一個PHP文件名爲foo.php和使用代碼類似於以下內容:

<?php 
/* 
Plugin Name: Name Of The Plugin 
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates 
Description: A brief description of the Plugin. 
Version: The Plugin's Version Number, e.g.: 1.0 
Author: Name Of The Plugin Author 
Author URI: http://URI_Of_The_Plugin_Author 
License: A "Slug" license name e.g. GPL2 
*/ 

    /** 
    * Foo_Widget Class 
    */ 
    class Foo_Widget extends WP_Widget { 
     /** constructor */ 
     function __construct() { 
      parent::WP_Widget(/* Base ID */'foo_widget', /* Name */'Foo_Widget', array('description' => 'A Foo Widget')); 
     } 
    /** @see WP_Widget::widget */ 
    function widget($args, $instance) { 
     extract($args); 
     $title = apply_filters('widget_title', $instance['title']); 
     echo $before_widget; 
     if ($title) 
      echo $before_title . $title . $after_title; ?> 
     <form action="" method="post"> 
        <input type="text" name="mytext" /> 
      <input type="text" name="result" value="<?php echo isset($_POST['mytext']) ? $_POST['mytext'] : ''; ?>" /> 
<input type="submit" name="submitbutton" value="Submit" /> </form> 
     <?php echo $after_widget; 
    } 

    /** @see WP_Widget::update */ 
    function update($new_instance, $old_instance) { 
     $instance = $old_instance; 
     $instance['title'] = strip_tags($new_instance['title']); 
     return $instance; 
    } 

    /** @see WP_Widget::form */ 
    function form($instance) { 
     if ($instance) { 
      $title = esc_attr($instance[ 'title' ]); 
     } 
     else { 
      $title = __('New title', 'text_domain'); 
     } 
     ?> 
     <p> 
     <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> 
     <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 
     </p> 
     <?php 
    } 

    } // class Foo_Widget 
    // register Foo_Widget widget 
    add_action('widgets_init', create_function('', 'register_widget("Foo_Widget");')); 
?> 
+0

謝謝!如果我在基本的wordpress acoount上,我可以使用它嗎? – Dims

+0

看起來你可以在自己託管的WordPress上使用它,但不能在wordpress.com基本賬戶上使用它。 –