Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ricky_Recent_Posts extends WP_Widget {
- function Ricky_Recent_Posts() {
- /* Widget settings. */
- $widget_ops = array(
- 'classname' => 'postsfromcat',
- 'description' => 'Allows you to display a list of recent posts from categories.');
- /* Widget control settings. */
- $control_ops = array(
- 'width' => 250,
- 'height' => 250,
- 'id_base' => 'postsfromcat-widget');
- /* Create the widget. */
- $this->WP_Widget('postsfromcat-widget', 'Ricky Recent Posts', $widget_ops, $control_ops );
- }
- function form ($instance) {
- /* Set up some default widget settings. ,'rss'=>''*/
- $defaults = array('numberposts' => '5','catid'=>'0','title'=>'','excluded'=>'mille');
- $instance = wp_parse_args( (array) $instance, $defaults ); ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>">Titolo:</label>
- <input type="text" name="<?php echo $this->get_field_name('title') ?>" id="<?php echo $this->get_field_id('title') ?> " value="<?php echo $instance['title'] ?>" size="20">
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('excluded'); ?>">Escludi Categoria ID:</label>
- <!-- < ?php wp_dropdown_categories('hide_empty=0&hierarchical=1&id='.$this->get_field_id('catid').'&name='.$this->get_field_name('catid').'&selected='.$instance['catid']); ? > -->
- <input type="text" name="<?php echo $this->get_field_id('excluded'); ?>" id="<?php echo $this->get_field_id('excluded'); ?>" value="<?php echo $instance['excluded'] ?>" size="20">
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('numberposts'); ?>">Numero di post:</label>
- <select id="<?php echo $this->get_field_id('numberposts'); ?>" name="<?php echo $this->get_field_name('numberposts'); ?>">
- <?php for ($i=1;$i<=20;$i++) {
- echo '<option value="'.$i.'"';
- if ($i==$instance['numberposts']) echo ' selected="selected"';
- echo '>'.$i.'</option>';
- } ?>
- </select>
- </p>
- <!--
- <p>
- <input type="checkbox" id="< ?php echo $this->get_field_id('rss'); ? >" name="< ?php echo $this->get_field_name('rss'); ? >" < ?php if ($instance['rss']) echo 'checked="checked"' ? > />
- <label for="< ?php echo $this->get_field_id('rss'); ? >">Show RSS feed link?</label>
- </p>
- -->
- <?php
- }
- function update ($new_instance, $old_instance) {
- $instance = $old_instance;
- $instance['excluded'] = $new_instance['excluded'];
- $instance['catid'] = $new_instance['catid'];
- $instance['numberposts'] = $new_instance['numberposts'];
- $instance['title'] = $new_instance['title'];
- // $instance['rss'] = $new_instance['rss'];
- return $instance;
- }
- function widget ($args,$instance) {
- extract($args);
- $excluded = $instance['excluded'];
- $title = $instance['title'];
- $catid = $instance['catid'];
- $numberposts = $instance['numberposts'];
- //$rss = $instance['rss'];
- // retrieve posts information from database '.$catid
- global $wpdb;
- $posts = get_posts('numberposts='.$numberposts.'&cat=-160,-169');
- $out = '<ul>';
- foreach($posts as $post) {
- $out .= '<li><strong><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></strong</li>';
- }
- //if ($rss) $out .= '<li><a href="'.get_category_link($catid).'feed/" class="rss">Category RSS</a></li>';
- $out .= '</ul>';
- //print the widget for the sidebar
- echo $before_widget;
- echo $before_title.$title.$after_title;
- echo $out;
- echo $after_widget;
- }
- }
- function ahspfc_load_widgets() {
- register_widget('Ricky_Recent_Posts');
- }
- add_action('widgets_init', 'ahspfc_load_widgets');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement