猿问

我的下拉列表只从 fornext 循环中获取一个项目

我正在创建允许用户从下拉列表中选择项目的小部件。我想出的是一个小部件,它有一个显示第一项的下拉列表。其余的像这样打印到屏幕上: Item 2 ; 第 3 项;输入新的事件名称。(标签)输入框


<?php


/* Plugin Name: Events Widget

  Description: This widget allows the user to select an Event name.

  Version: 0.5

  Author: Dan Statham

  Author URI:

  License: GPLv2

 */

function gdd_Events_load_widgets() {

    write_log('gdd _Events_load_widgets');

}// gdd_Events_load_widgets


// Register the widget

function my_register_custom_widget() {

    register_widget( 'gdd_Events_load_widgets' );

} //  echo('registerd');


function submit(){

   if(isset($_POST['submit'])){

      $selected_val = $_POST['Color'];  // Storing Selected Value In Variable

     echo "You have selected :" .$selected_val;  // Displaying Selected Value

}


}

add_action( 'widgets_init', 'my_register_custom_widget' );  



// The widget class

class gdd_Events_load_widgets extends WP_Widget {

    function gdd_Events_Widget() {

        /* Widget settings. */

        $widget_ops = array( 'classname' => 'event', 

                    'description' => __('Allow the user to select an Event name.', 'event') );


        /* Widget control settings. */

        $control_ops = array( 'width' => 200, 'height' => 150, 'id_base' => 'gdd_Events_Widget' );


        /* Create the widget. */

        $this->WP_Widget( 'Event', __('Event Name', 'event'), $widget_ops, $control_ops );

    } // function gdd_Events_Widget

    // Main constructor

    function __construct() {

        parent::__construct(                

                // base ID of the widget

                'gdd_Events_Widget',

                // name of the widget

                __('Event Name dropdown', 'events'),

                // widget options

                array(

                    'description' => __('Select the Event name.',

                            'events')

               )

        ); //parent __construct()

    }//function __construct()

任何人都可以告诉我我的方法的错误以及如何让它工作吗?


慕的地6264312
浏览 121回答 1
1回答

慕森卡

<?php&nbsp;&nbsp;&nbsp;foreach ($events as $event) {?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option value=" <?php echo $event['id'] ?>"><?php echo $event['event']; ?></option>;</select>&nbsp; &nbsp;&nbsp;<?php}&nbsp;&nbsp;请将标记放在 foreach 循环之外<?php&nbsp;&nbsp;&nbsp;foreach ($events as $event) {?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<option value=" <?php echo $event['id'] ?>"><?php echo $event['event']; ?></option>;<?php} ?></select>&nbsp; &nbsp;&nbsp;
随时随地看视频慕课网APP
我要回答