Last active
November 25, 2015 17:20
-
-
Save duroe5698/f10fe5a5963f40e37ace to your computer and use it in GitHub Desktop.
Custom WordPress Genesis Loop Widget
This file contains hidden or 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 | |
| class YOURCUSTOMWidget extends WP_Widget | |
| { | |
| function YOURCUSTOMWidget() | |
| { | |
| $widget_ops = array('classname' => 'YOURCUSTOMWidget', 'description' => 'Widget Description' ); | |
| parent::__construct('YOURCUSTOMWidget', 'YOURCUSTOM Widget', $widget_ops); | |
| } | |
| function form($instance) | |
| { | |
| $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); | |
| $title = $instance['title']; | |
| ?> | |
| <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> | |
| <?php | |
| } | |
| function update($new_instance, $old_instance) | |
| { | |
| $instance = $old_instance; | |
| $instance['title'] = $new_instance['title']; | |
| return $instance; | |
| } | |
| function widget($args, $instance) | |
| { | |
| extract($args, EXTR_SKIP); | |
| echo $before_widget; | |
| $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); | |
| if (!empty($title)) | |
| echo $before_title . $title . $after_title;; | |
| // WIDGET CODE STARTS HERE | |
| global $post; | |
| $args = array( | |
| 'post_type' => 'POST TYPE', | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => 4, | |
| 'orderby' => 'date', | |
| 'order' => 'ASC', | |
| 'no_found_rows' => true, | |
| ); | |
| global $wp_query; | |
| $wp_query = new WP_Query( $args ); | |
| if ( ! genesis_html5() ) { | |
| genesis_legacy_loop(); | |
| return; | |
| } | |
| if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); | |
| //*Begin post meta variables | |
| //*End post meta variables | |
| //*Loop Code Goes Here | |
| endwhile; //* end of one post | |
| do_action( 'genesis_after_endwhile' ); | |
| else : //* if no posts exist | |
| do_action( 'genesis_loop_else' ); | |
| endif; //* end loop | |
| wp_reset_query(); | |
| // WIDGET CODE ENDS HERE | |
| echo $after_widget; | |
| } | |
| } | |
| add_action( 'widgets_init', create_function('', 'return register_widget("YOURCUSTOMWidget");') ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment