In fact, the latest article code to add a sorting filter just to make a small tool is convenient to arrange the side bar display position.
WordPress Gadget: The latest article with sorting filter feature
1. Support the number of articles set (nonsense), the default is 5
2. All Categories drop-down box directly select the classification, convenient (lazy people)
3. No, simple function
Method:
1. Throw the following code into the theme of the functions.php, certainly in the <php ...? > Inside
////////latest article with filter feature//adds Zww_recent_posts_widget widget.classZww_recent_posts_widgetextendsWp_widget {//Register widget with WordPress. Public function__construct () {Parent::__construct (' Zww_recent_posts_widget ',//Base ID' Zww\ 's latest article ',//Name Array(' description ' + ' up-to-date article with sorting filter feature ', ')//Args ); } Public functionWidget$args,$instance ) { Extract($args ); $title= Apply_filters (' Widget_title ',$instance[' title '] ); $post _num= Apply_filters (' Widget_title ',$instance[' Post_num '] ); $catID= Apply_filters (' Widget_title ',$instance[' CatID '] ); Echo $before _widget; if( !Empty($title ) ) Echo $before _title.$title.$after _title;?> <ul> <?PHPGlobal $post; $tmp _post=$post; $recent _posts= Get_posts (' orderby=asc&numberposts= ').$post _num.‘ &category= '.$catID); foreach($recent _posts as $post) {Setup_postdata ($post);?> <li><a href= "<?php the_permalink"?> "title=" <?php the_title ();?> ">< ? php the_title ();?></a></li> <?php}$post=$tmp _post; Setup_postdata ($post);?> </ul> <?PHPEcho $after _widget; } Public functionUpdate$new _instance,$old _instance ) { $instance=Array(); $instance[' title '] =Strip_tags($new _instance[' title '] ); $instance[' post_num '] =Strip_tags($new _instance[' Post_num '] ); $instance[' catID '] =Strip_tags($new _instance[' CatID '] ); return $instance; } Public functionForm$instance ) { if(isset($instance[' title ' ] ) ) { $title=$instance[' title ' ]; } Else { $title= ' recent Posts '; } if(isset($instance[' Post_num ' ] ) ) { $post _num=$instance[' Post_num ' ]; } Else { $post _num= 5; } if(isset($instance[' CatID ' ] ) ) { $catID=$instance[' CatID ' ]; } Else { $catID= ' '; } ?> <p> <label for= "<?php Echo$this->get_field_id (' title ');?> "> Title:</label> <inputclass= "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);?> "/> <label for= "<?php Echo$this->get_field_id (' Post_num ');?> "> Display quantity:</label> <inputclass= "Widefat" id= "<?php Echo$this->get_field_id (' Post_num ');?> "Name=" <?php Echo$this->get_field_name (' Post_num ');?> "type=" text "value=" <?php Echo esc_attr ($post _num);?> "/> <label for= "<?php Echo$this->get_field_id (' slug ');?> "> select category:</label> <?php wp_dropdown_categories (Array( ' Name ' + =$this->get_field_name (' CatID '), ' hide_empty ' = 0, ' by ' ' Show_count ' = 1, ' selected ' and esc_attr ($catID), ' hierarchical ' =true, ' Show_option_none ' and ' All categories ', ' echo ' = 1 )); ?> </p> <?php}} //class zww_recent_posts_widget//Register Zww_recent_posts_widget widgetAdd_action (' Widgets_init ',create_function(', ' Register_widget ("Zww_recent_posts_widget"); );
2. Then go to the "appearance" gadget, and find the widget area like, drag to the right side sidebar
3. And then, you know.
That's it.
WP Widget: The latest article widget with sorting filter features