Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class EventTags extends WP_Widget {
- public function __construct() {
- // Instantiate the parent object
- parent::__construct(
- 'event-tags', // Base ID
- 'Event tags', // Name
- array(
- 'classname' => 'widget--event tags',
- 'description' => 'Shows event tags'
- ) // Args
- );
- }
- public function widget( $args, $instance ) {
- $term_args = array(
- 'taxonomy' => 'event-tags',
- 'orderby' => 'count',
- 'order' => 'DESC',
- 'number' => 10,
- );
- $terms = get_terms( $term_args );
- // Widget output
- extract( $args );
- $etw_widgettitle = apply_filters( 'widget_title', $instance['etw_widgettitle'] );
- echo $before_widget;
- if ( $etw_widgettitle ) {
- echo $before_title . $etw_widgettitle . $after_title;
- }
- if ( $terms ) {
- echo '<ul>';
- foreach( $terms as $term ) {
- echo '<li><a href="' . get_term_link( $term->term_taxonomy_id ) . '">' . $term->name . '</a></li>';
- }
- echo '</ul>';
- }
- echo $after_widget;
- }
- public function update( $new_instance, $old_instance ) {
- // Save widget options
- $instance = $old_instance;
- $instance['etw_widgettitle'] = strip_tags($new_instance['etw_widgettitle']);
- return $instance;
- }
- public function form( $instance ) {
- // Output admin widget options form
- $etw_widgettitle = ! empty( $instance['etw_widgettitle'] ) ? $instance['etw_widgettitle'] : esc_html__( 'Event tags', 'text_domain' );
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('etw_widgettitle'); ?>">Widget title:</label>
- <input class="widefat" id="<?php echo $this->get_field_id('etw_widgettitle'); ?>" name="<?php echo $this->get_field_name('etw_widgettitle'); ?>" type="text" value="<?php if ( $etw_widgettitle ) { echo $etw_widgettitle; } ?>" />
- </p>
- <?php }
- }
- function register_my_widgets() {
- if ( function_exists( 'em_content' ) ) {
- register_widget( 'EventTags' );
- }
- }
- add_action( 'widgets_init', 'register_my_widgets' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement