Advertisement
Guest User

Untitled

a guest
Sep 20th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.58 KB | None | 0 0
  1. class Ricky_Recent_Posts extends WP_Widget {
  2.  
  3.   function Ricky_Recent_Posts() {
  4.      /* Widget settings. */
  5.     $widget_ops = array(
  6.       'classname' => 'postsfromcat',
  7.       'description' => 'Allows you to display a list of recent posts from categories.');
  8.  
  9.      /* Widget control settings. */
  10.     $control_ops = array(
  11.        'width' => 250,
  12.        'height' => 250,
  13.        'id_base' => 'postsfromcat-widget');
  14.  
  15.     /* Create the widget. */
  16.    $this->WP_Widget('postsfromcat-widget', 'Ricky Recent Posts', $widget_ops, $control_ops );
  17.   }
  18.  
  19.   function form ($instance) {
  20.     /* Set up some default widget settings. ,'rss'=>''*/
  21.     $defaults = array('numberposts' => '5','catid'=>'0','title'=>'','excluded'=>'mille');
  22.     $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  23.  
  24.   <p>
  25.     <label for="<?php echo $this->get_field_id('title'); ?>">Titolo:</label>
  26.     <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">
  27.   </p>
  28.  
  29.   <p>
  30.    <label for="<?php echo $this->get_field_id('excluded'); ?>">Escludi Categoria ID:</label>
  31.    <!-- < ?php wp_dropdown_categories('hide_empty=0&hierarchical=1&id='.$this->get_field_id('catid').'&name='.$this->get_field_name('catid').'&selected='.$instance['catid']); ? > -->  
  32.    <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">
  33.   </p>
  34.  
  35.   <p>
  36.    <label for="<?php echo $this->get_field_id('numberposts'); ?>">Numero di post:</label>
  37.    <select id="<?php echo $this->get_field_id('numberposts'); ?>" name="<?php echo $this->get_field_name('numberposts'); ?>">
  38.    <?php for ($i=1;$i<=20;$i++) {
  39.          echo '<option value="'.$i.'"';
  40.          if ($i==$instance['numberposts']) echo ' selected="selected"';
  41.          echo '>'.$i.'</option>';
  42.         } ?>
  43.        </select>
  44.   </p>
  45.  
  46.  <!--
  47.   <p>
  48.    <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"' ? > />
  49.    <label for="< ?php echo $this->get_field_id('rss'); ? >">Show RSS feed link?</label>
  50.   </p>
  51.      -->
  52.   <?php
  53. }
  54.  
  55. function update ($new_instance, $old_instance) {
  56.   $instance = $old_instance;
  57.  
  58.   $instance['excluded'] = $new_instance['excluded'];
  59.   $instance['catid'] = $new_instance['catid'];
  60.   $instance['numberposts'] = $new_instance['numberposts'];
  61.   $instance['title'] = $new_instance['title'];
  62.  
  63.  // $instance['rss'] = $new_instance['rss'];
  64.  
  65.   return $instance;
  66. }
  67.  
  68. function widget ($args,$instance) {
  69.    extract($args);
  70.  
  71.   $excluded = $instance['excluded'];
  72.   $title = $instance['title'];
  73.   $catid = $instance['catid'];
  74.   $numberposts = $instance['numberposts'];
  75.  
  76.   //$rss = $instance['rss'];
  77.  
  78.   // retrieve posts information from database '.$catid
  79.   global $wpdb;
  80.   $posts = get_posts('numberposts='.$numberposts.'&cat=-160,-169');
  81.   $out = '<ul>';
  82.   foreach($posts as $post) {
  83.   $out .= '<li><strong><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></strong</li>';
  84.   }
  85.   //if ($rss) $out .= '<li><a href="'.get_category_link($catid).'feed/" class="rss">Category RSS</a></li>';
  86.   $out .= '</ul>';
  87.  
  88.   //print the widget for the sidebar
  89.   echo $before_widget;
  90.   echo $before_title.$title.$after_title;
  91.   echo $out;
  92.   echo $after_widget;
  93.  }
  94. }
  95.  
  96. function ahspfc_load_widgets() {
  97.   register_widget('Ricky_Recent_Posts');
  98. }
  99.  
  100. add_action('widgets_init', 'ahspfc_load_widgets');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement