Forked from danielpataki/display-skeleton.php
Last active
September 13, 2015 17:35
-
-
Save barbietunnie/2e040297be73bcf08c79 to your computer and use it in GitHub Desktop.
Creating An Authors Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function widget( $args, $instance ) { | |
echo $args['before_widget']; | |
if( !empty( $instance['title'] ) ) { | |
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; | |
} | |
// Main Widget Code Here | |
echo $args['after_widget']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wp_enqueue_style( 'my-author-list' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_enqueue_scripts', array( $this, 'widget_styles' ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function form( $instance ) { | |
// Field Values | |
$title = ( !empty( $instance['title'] ) ) ? $instance['title'] : ''; | |
$count = ( !empty( $instance['count'] ) ) ? $instance['count'] : 5; | |
$orderby = ( !empty( $instance['orderby'] ) ) ? $instance['orderby'] : 'post_count'; | |
$order = ( !empty( $instance['order'] ) ) ? $instance['order'] : 'desc'; | |
// Field Options | |
$orderby_options = array( | |
'ID' => 'ID' | |
'email' => 'Email' | |
'post_count' => 'Post Count' | |
); | |
$order_options = array( | |
'desc' => 'Descending', | |
'asc' => 'Ascending' | |
); | |
?> | |
<div class='unread-posts'> | |
<p> | |
<label for="<?php echo $this->get_field_name( 'title' ); ?>">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 esc_attr( $title ); ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_name( 'count' ); ?>">Authors To Show: </label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" type="text" value="<?php echo esc_attr( $count ); ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_name( 'orderby' ); ?>">Order By: </label> | |
<select class='widefat' id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>"> | |
<?php foreach( $orderby_options as $value => $name ) : ?> | |
<option <?php selected( $orderby, $value ) ?> value='<?php echo $value ?>'><?php echo $name ?></option> | |
<?php endforeach ?> | |
</select> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_name( 'order' ); ?>">Order By: </label> | |
<select class='widefat' id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>"> | |
<?php foreach( $orderby_options as $value => $name ) : ?> | |
<option <?php selected( $order, $value ) ?> value='<?php echo $value ?>'><?php echo $name ?></option> | |
<?php endforeach ?> | |
</select> | |
</p> | |
</div> | |
<?php | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $args = array( | |
'blog_id' => $GLOBALS['blog_id'], | |
'role' => '', | |
'meta_key' => '', | |
'meta_value' => '', | |
'meta_compare' => '', | |
'meta_query' => array(), | |
'include' => array(), | |
'exclude' => array(), | |
'orderby' => 'login', | |
'order' => 'ASC', | |
'offset' => '', | |
'search' => '', | |
'number' => '', | |
'count_total' => false, | |
'fields' => 'all', | |
'who' => '' | |
); ?> | |
$args = array( | |
'who' => 'authors', | |
'number' => $instance['count'], | |
'orderby' => $instance['orderby'], | |
'order' => $instance['order'], | |
); | |
$users = get_users( $args ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: My Author List | |
* Plugin URI: http://danielpataki.com | |
* Description: This widget displays a list of authors. | |
* Version: 1.0.0 | |
* Author: Daniel Pataki | |
* Author URI: http://danielpataki.com | |
* License: GPL2 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function widget_styles() { | |
wp_register_style( 'my-author-list', plugin_dir_url( __FILE__ ) . 'my-author-list.css' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'ta/post_query', 'my_ta_post_query', 10, 2 ); | |
function my_ta_post_query( $query_args, $instance ) { | |
$query_args['date_query'] = array( | |
array( | |
'dayofweek' => array( 2,6 ), | |
'compare' => 'NOT BETWEEN', | |
), | |
); | |
$query_args['category_name'] = 'featured'; | |
return $query_args; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if( !empty( $users ) ) { | |
echo '<ul>'; | |
foreach( $users as $user ) { | |
echo '<li>'; | |
echo '<a href="' . $user->user_url . '">' . get_avatar( $user->ID, 64 ) . '</a>'; | |
echo '<a href="' . $user->user_url . '">' . $user->display_name . '</a>'; | |
echo '</li>'; | |
} | |
echo '</ul>'; | |
} | |
else { | |
echo 'No Users To Show'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class My_Author_List_Widget extends WP_Widget { | |
public function __construct() { | |
$widget_details = array( | |
'classname' => 'my-author-list', | |
'description' => 'A simple author display widget' | |
); | |
parent::__construct( 'my-author-list', 'My Author List', $widget_details ); | |
} | |
public function form( $instance ) { | |
} | |
public function widget( $args, $instance ) { | |
} | |
public function update( $new_instance, $old_instance ) { | |
} | |
} | |
add_action( 'widgets_init', function(){ | |
register_widget( 'My_Author_List_Widget' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment