new widget
-
Create for my site widget with birth days person.
for create need create 1 new file, and edit 2 exists files.in file rootspersona.php
add line #52
require_once WP_PLUGIN_DIR . '/rootspersona/surname_widget_birth.php';
in file /php/dao/mysql/class-RP-Persona-Mysql-DAO.php
add text from line 189public function get_names_birth($cnt) { if (!isset($cnt) || empty($cnt)) $cnt = 10; $sql = "SELECT CONCAT_WS(' ', NULLIF(rnp.surname,''), ' ', NULLIF(rnp.given,''), ' ', NULLIF(rnp.suffix,'')) AS surname," . " DATE_FORMAT(STR_TO_DATE(red.event_date, '%d %b %Y'),'%d.%m.%Y') as cnt" . " FROM rp_indi ri" . " JOIN rp_indi_name rip ON ri.id = rip.indi_id AND ri.batch_id = rip.indi_batch_id" . " JOIN rp_name_personal rnp ON rip.name_id = rnp.id" . " JOIN rp_indi_event rie ON rip.indi_id = rie.indi_id" . " JOIN rp_event_detail red ON red.id = rie.event_id and red.event_type = 'Birth'" . " WHERE DATE_FORMAT(STR_TO_DATE(red.event_date, '%d %b %Y'),'%d.%m.%Y') is not null" . " AND MONTH(now()) = MONTH(STR_TO_DATE(red.event_date, '%d %b %Y'))" . " ORDER BY 2 LIMIT 0," . $cnt; $sql_query = new RP_Sql_Query($sql); $rows = RP_Query_Executor::execute($sql_query); return $rows; }
new file surname_widget_birth.php
<?php /** * Add function to widgets_init that'll load our widget. * @since 0.1 */ add_action( 'widgets_init', 'birth_load_widgets' ); /** * Register our widget. * 'Example_Widget' is the widget class used below. * * @since 0.1 */ function birth_load_widgets() { register_widget( 'Surname_Widget_birth' ); } /** * Example Widget class. * This class handles everything that needs to be handled with the widget: * the settings, form, display, and update. Nice! * * @since 0.1 */ class Surname_Widget_birth extends WP_Widget { function __construct() { /* Widget settings. */ $widget_ops = array( 'classname' => 'rpSurnameWidgetBirth', 'description' => __('An widget that displays the birth.', 'rootspersona') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'rp_surname_widget_birth' ); /* Create the widget. */ parent::__construct('rp_surname_widget_birth', __('Birthdays in this month', 'rootspersona'), $widget_ops, $control_ops ); } function Surname_Widget_birth() { $this->construct(); } /** * How to display the widget on the screen. */ function widget( $args, $instance ) { global $wpdb, $before_widget, $before_title, $after_title, $after_widget; extract( $args ); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title'] ); $cnt = $instance['cnt']; /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) echo $before_title . $title . $after_title; /* Display name from widget settings if one was input. */ if ( $cnt > 0 ) { $creds = new RP_Credentials(); $creds->set_prefix( $wpdb->prefix ); $transaction = new RP_Transaction( $creds, false ); $rows = RP_Dao_Factory::get_rp_persona_dao( $creds ) ->get_names_birth( $cnt ); $rCnt = count($rows); if($rCnt > 0 ) { for($idx = 0; $idx < $rCnt; $idx++ ) { //echo '<div style="margin-left:10px;">' . $rows[$idx]['surname'] . ' (' . $rows[$idx]['cnt'] . ')</div>'; echo '<div style="margin-left:10px;">' . $rows[$idx]['cnt'] . ' <a href="' . get_home_url(null,'/?s=' . $rows[$idx]['surname'] . '&posttype=page&widget=advanced-search-widget-3') . '" rel="nofollow">' . $rows[$idx]['surname'] . '</a></div>'; } } $transaction->close(); } /* After widget (defined by themes). */ echo $after_widget; } /** * Update the widget settings. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['cnt'] = strip_tags( $new_instance['cnt'] ); return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' => __('Birthdays in this month', 'rootspersona'), 'cnt' => '10' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!-- Widget Title: Text Input --> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label> <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" /> </p> <!-- Your Name: Text Input --> <p> <label for="<?php echo $this->get_field_id( 'cnt' ); ?>"><?php _e('How Many:', 'example'); ?></label> <input id="<?php echo $this->get_field_id( 'cnt' ); ?>" name="<?php echo $this->get_field_name( 'cnt' ); ?>" value="<?php echo $instance['cnt']; ?>" style="width:100%;" /> </p> <?php } } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘new widget’ is closed to new replies.