Advertisement
towfiqi

widget.php

Mar 1st, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.02 KB | None | 0 0
  1. <?php
  2. /*
  3.  *CUSTOM 125x125 AD
  4.  */
  5. add_action( 'widgets_init', 'trt_ad125x125_widgets' );
  6.  
  7. /*
  8.  * Register widget.
  9.  */
  10. function trt_ad125x125_widgets() {
  11.     register_widget( 'trt_Ad125x125_Widget' );
  12. }
  13.  
  14. /*
  15.  * Widget class.
  16.  */
  17. class trt_ad125x125_widget extends WP_Widget {
  18.  
  19.     /* ---------------------------- */
  20.     /* -------- Widget setup -------- */
  21.     /* ---------------------------- */
  22.    
  23.     function trt_Ad125x125_Widget() {
  24.    
  25.         /* Widget settings */
  26.         $widget_ops = array( 'classname' => 'trt_ad125x125_widget', 'description' => __('A Triton widget that allows the display and configuration of of a single 125x125 Banner.', 'Triton') );
  27.  
  28.         /* Widget control settings */
  29.         //$control_ops = array( 'width' => 125, 'height' => 125, 'id_base' => 'trt_ad125_widget' );
  30.  
  31.         /* Create the widget */
  32.         $this->WP_Widget( 'trt_ad125x125_widget', __('Custom 125x125 Ad', 'Triton'), $widget_ops );
  33.     }
  34.  
  35.     /* ---------------------------- */
  36.     /* ------- Display Widget -------- */
  37.     /* ---------------------------- */
  38.    
  39.     function widget( $args, $instance ) {
  40.         extract( $args );
  41.  
  42.         /* Our variables from the widget settings. */
  43.         $title = apply_filters('widget_title', $instance['title'] );
  44.         $ad = $instance['ad'];
  45.         $link = $instance['link'];
  46.         $ad2 = $instance['ad2'];
  47.         $link2 = $instance['link2'];
  48.  
  49.         /* Before widget (defined by themes). */
  50.         echo $before_widget;
  51.  
  52.         /* Display the widget title if one was input (before and after defined by themes). */
  53.         if ( $title )
  54.             echo $before_title . $title . $after_title;
  55.            
  56.         /* Display a containing div */
  57.         echo '<div class="ads-125x125">';
  58.  
  59.         /* Display Ad */
  60.         if ( $link )
  61.             echo '<a target="_blank" href="' . $link . '"><img src="' . $ad . '" width="125" height="125"  /></a>';
  62.            
  63.         elseif ( $ad )
  64.             echo '<img src="' . $ad . '" width="125" height="125" alt="" />';
  65.            
  66.                 /* Display Ad */
  67.         if ( $link2 )
  68.             echo '<a target="_blank" href="' . $link2 . '"><img src="' . $ad2 . '" width="125" height="125"  /></a>';
  69.            
  70.         elseif ( $ad2 )
  71.             echo '<img src="' . $ad2 . '" width="125" height="125" alt="" />';
  72.            
  73.         echo '</div>';
  74.  
  75.         /* After widget (defined by themes). */
  76.         echo $after_widget;
  77.     }
  78.  
  79.     /* ---------------------------- */
  80.     /* ------- Update Widget -------- */
  81.     /* ---------------------------- */
  82.    
  83.     function update( $new_instance, $old_instance ) {
  84.         $instance = $old_instance;
  85.  
  86.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  87.         $instance['title'] = strip_tags( $new_instance['title'] );
  88.  
  89.         /* No need to strip tags */
  90.         $instance['ad'] = $new_instance['ad'];
  91.         $instance['link'] = $new_instance['link'];
  92.         $instance['ad2'] = $new_instance['ad2'];
  93.         $instance['link2'] = $new_instance['link2'];
  94.  
  95.         return $instance;
  96.     }
  97.    
  98.     /* ---------------------------- */
  99.     /* ------- Widget Settings ------- */
  100.     /* ---------------------------- */
  101.    
  102.     /**
  103.      * Displays the widget settings controls on the widget panel.
  104.      * Make use of the get_field_id() and get_field_name() function
  105.      * when creating your form elements. This handles the confusing stuff.
  106.      */
  107.    
  108.     function form( $instance ) {
  109.    
  110.         /* Set up some default widget settings. */
  111.         $defaults = array(
  112.         'title' => '',
  113.         'ad' => get_template_directory_uri()."/images/defaults/banner_200.jpg",
  114.         'link' => 'http://www.towfiqi.com',
  115.         'ad2' => get_template_directory_uri()."/images/defaults/banner_200.jpg",
  116.         'link2' => 'http://www.towfiqi.com',
  117.         );
  118.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  119.  
  120.  
  121.         <!-- Widget Title: Text Input -->
  122.         <p>
  123.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  124.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  125.         </p>
  126.         <strong><?php _e('1st Ad block','Triton');?></strong>
  127.         <!-- Ad image url: Text Input -->
  128.         <p>
  129.             <label for="<?php echo $this->get_field_id( 'ad' ); ?>"><?php _e('Ad image url:', 'Triton') ?></label>
  130.             <input class="widefat" id="<?php echo $this->get_field_id( 'ad' ); ?>" name="<?php echo $this->get_field_name( 'ad' ); ?>" value="<?php echo $instance['ad']; ?>" />
  131.         </p>
  132.        
  133.         <!-- Ad link url: Text Input -->
  134.         <p>
  135.             <label for="<?php echo $this->get_field_id( 'link' ); ?>"><?php _e('Ad link url:', 'Triton') ?></label>
  136.             <input class="widefat" id="<?php echo $this->get_field_id( 'link' ); ?>" name="<?php echo $this->get_field_name( 'link' ); ?>" value="<?php echo $instance['link']; ?>" />
  137.         </p>
  138.        
  139.        
  140.         <strong><?php _e('2nd Ad block','Triton');?></strong>        
  141.                 <!-- Ad image url: Text Input -->
  142.         <p>
  143.             <label for="<?php echo $this->get_field_id( 'ad2' ); ?>"><?php _e('Ad image url:', 'Triton') ?></label>
  144.             <input class="widefat" id="<?php echo $this->get_field_id( 'ad2' ); ?>" name="<?php echo $this->get_field_name( 'ad2' ); ?>" value="<?php echo $instance['ad2']; ?>" />
  145.         </p>
  146.        
  147.         <!-- Ad link url: Text Input -->
  148.         <p>
  149.             <label for="<?php echo $this->get_field_id( 'link2' ); ?>"><?php _e('Ad link url:', 'Triton') ?></label>
  150.             <input class="widefat" id="<?php echo $this->get_field_id( 'link2' ); ?>" name="<?php echo $this->get_field_name( 'link2' ); ?>" value="<?php echo $instance['link2']; ?>" />
  151.         </p>
  152.        
  153.     <?php
  154.     }
  155.  
  156. }
  157.  
  158. /*
  159.  *CUSTOM 250x250 AD
  160.  */
  161. add_action( 'widgets_init', 'trt_ad250x250_widgets' );
  162.  
  163. /*
  164.  * Register widget.
  165.  */
  166. function trt_ad250x250_widgets() {
  167.     register_widget( 'trt_Ad250x250_Widget' );
  168. }
  169.  
  170. /*
  171.  * Widget class.
  172.  */
  173. class trt_ad250x250_widget extends WP_Widget {
  174.  
  175.     /* ---------------------------- */
  176.     /* -------- Widget setup -------- */
  177.     /* ---------------------------- */
  178.    
  179.     function trt_Ad250x250_Widget() {
  180.    
  181.         /* Widget settings */
  182.         $widget_ops = array( 'classname' => 'trt_ad250x250_widget', 'description' => __('A Triton widget that allows the display and configuration of of a single 250x250 Banner.', 'Triton') );
  183.  
  184.         /* Widget control settings */
  185.         //$control_ops = array( 'width' => 250, 'height' => 250, 'id_base' => 'trt_ad250_widget' );
  186.  
  187.         /* Create the widget */
  188.         $this->WP_Widget( 'trt_ad250x250_widget', __('Custom 250x250 Ad', 'Triton'), $widget_ops );
  189.     }
  190.  
  191.     /* ---------------------------- */
  192.     /* ------- Display Widget -------- */
  193.     /* ---------------------------- */
  194.    
  195.     function widget( $args, $instance ) {
  196.         extract( $args );
  197.  
  198.         /* Our variables from the widget settings. */
  199.         $title = apply_filters('widget_title', $instance['title'] );
  200.         $ad = $instance['ad'];
  201.         $link = $instance['link'];
  202.  
  203.         /* Before widget (defined by themes). */
  204.         echo $before_widget;
  205.  
  206.         /* Display the widget title if one was input (before and after defined by themes). */
  207.         if ( $title )
  208.             echo $before_title . $title . $after_title;
  209.            
  210.         /* Display a containing div */
  211.         echo '<div class="ads-250x250">';
  212.  
  213.         /* Display Ad */
  214.         if ( $link )
  215.             echo '<a target="_blank" href="' . $link . '"><img src="' . $ad . '" width="250" height="250"  alt="" /></a>';
  216.            
  217.         elseif ( $ad )
  218.             echo '<img src="' . $ad . '" width="250" height="250" alt="" />';
  219.            
  220.         echo '</div>';
  221.  
  222.         /* After widget (defined by themes). */
  223.         echo $after_widget;
  224.     }
  225.  
  226.     /* ---------------------------- */
  227.     /* ------- Update Widget -------- */
  228.     /* ---------------------------- */
  229.    
  230.     function update( $new_instance, $old_instance ) {
  231.         $instance = $old_instance;
  232.  
  233.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  234.         $instance['title'] = strip_tags( $new_instance['title'] );
  235.  
  236.         /* No need to strip tags */
  237.         $instance['ad'] = $new_instance['ad'];
  238.         $instance['link'] = $new_instance['link'];
  239.  
  240.         return $instance;
  241.     }
  242.    
  243.     /* ---------------------------- */
  244.     /* ------- Widget Settings ------- */
  245.     /* ---------------------------- */
  246.    
  247.     /**
  248.      * Displays the widget settings controls on the widget panel.
  249.      * Make use of the get_field_id() and get_field_name() function
  250.      * when creating your form elements. This handles the confusing stuff.
  251.      */
  252.    
  253.     function form( $instance ) {
  254.    
  255.         /* Set up some default widget settings. */
  256.         $defaults = array(
  257.         'title' => '',
  258.         'ad' => get_template_directory_uri()."/images/defaults/banner_200.jpg",
  259.         'link' => 'http://www.towfiqi.com',
  260.         );
  261.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  262.  
  263.         <!-- Widget Title: Text Input -->
  264.         <p>
  265.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  266.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  267.         </p>
  268.  
  269.         <!-- Ad image url: Text Input -->
  270.         <p>
  271.             <label for="<?php echo $this->get_field_id( 'ad' ); ?>"><?php _e('Ad image url:', 'Triton') ?></label>
  272.             <input class="widefat" id="<?php echo $this->get_field_id( 'ad' ); ?>" name="<?php echo $this->get_field_name( 'ad' ); ?>" value="<?php echo $instance['ad']; ?>" />
  273.         </p>
  274.        
  275.         <!-- Ad link url: Text Input -->
  276.         <p>
  277.             <label for="<?php echo $this->get_field_id( 'link' ); ?>"><?php _e('Ad link url:', 'Triton') ?></label>
  278.             <input class="widefat" id="<?php echo $this->get_field_id( 'link' ); ?>" name="<?php echo $this->get_field_name( 'link' ); ?>" value="<?php echo $instance['link']; ?>" />
  279.         </p>
  280.        
  281.     <?php
  282.     }
  283.  
  284. }
  285.  
  286. /*
  287.  *CUSTOM 160x600 AD
  288.  */
  289. add_action( 'widgets_init', 'trt_ad160x600_widgets' );
  290.  
  291. /*
  292.  * Register widget.
  293.  */
  294. function trt_ad160x600_widgets() {
  295.     register_widget( 'trt_Ad160x600_Widget' );
  296. }
  297.  
  298. /*
  299.  * Widget class.
  300.  */
  301. class trt_ad160x600_widget extends WP_Widget {
  302.  
  303.     /* ---------------------------- */
  304.     /* -------- Widget setup -------- */
  305.     /* ---------------------------- */
  306.    
  307.     function trt_Ad160x600_Widget() {
  308.    
  309.         /* Widget settings */
  310.         $widget_ops = array( 'classname' => 'trt_ad160x600_widget', 'description' => __('A Triton widget that allows the display and configuration of of a single 160x600 Banner.', 'Triton') );
  311.  
  312.         /* Widget control settings */
  313.         //$control_ops = array( 'width' => 160, 'height' => 600, 'id_base' => 'trt_ad160x600_widget' );
  314.  
  315.         /* Create the widget */
  316.         $this->WP_Widget( 'trt_ad160x600_widget', __('Custom 160x600 Ad', 'Triton'), $widget_ops );
  317.     }
  318.  
  319.     /* ---------------------------- */
  320.     /* ------- Display Widget -------- */
  321.     /* ---------------------------- */
  322.    
  323.     function widget( $args, $instance ) {
  324.         extract( $args );
  325.  
  326.         /* Our variables from the widget settings. */
  327.         $title = apply_filters('widget_title', $instance['title'] );
  328.         $ad = $instance['ad'];
  329.         $link = $instance['link'];
  330.  
  331.         /* Before widget (defined by themes). */
  332.         echo $before_widget;
  333.  
  334.         /* Display the widget title if one was input (before and after defined by themes). */
  335.         if ( $title )
  336.             echo $before_title . $title . $after_title;
  337.            
  338.         /* Display a containing div */
  339.         echo '<div class="ads-160x600">';
  340.  
  341.         /* Display Ad */
  342.         if ( $link )
  343.             echo '<a target="_blank" href="' . $link . '"><img src="' . $ad . '" width="160" height="600" alt="" /></a>';
  344.            
  345.         elseif ( $ad )
  346.             echo '<img src="' . $ad . '" width="160" height="600" alt="" />';
  347.            
  348.         echo '</div>';
  349.  
  350.         /* After widget (defined by themes). */
  351.         echo $after_widget;
  352.     }
  353.  
  354.     /* ---------------------------- */
  355.     /* ------- Update Widget -------- */
  356.     /* ---------------------------- */
  357.    
  358.     function update( $new_instance, $old_instance ) {
  359.         $instance = $old_instance;
  360.  
  361.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  362.         $instance['title'] = strip_tags( $new_instance['title'] );
  363.  
  364.         /* No need to strip tags */
  365.         $instance['ad'] = $new_instance['ad'];
  366.         $instance['link'] = $new_instance['link'];
  367.  
  368.         return $instance;
  369.     }
  370.    
  371.     /* ---------------------------- */
  372.     /* ------- Widget Settings ------- */
  373.     /* ---------------------------- */
  374.    
  375.     /**
  376.      * Displays the widget settings controls on the widget panel.
  377.      * Make use of the get_field_id() and get_field_name() function
  378.      * when creating your form elements. This handles the confusing stuff.
  379.      */
  380.    
  381.     function form( $instance ) {
  382.    
  383.         /* Set up some default widget settings. */
  384.         $defaults = array(
  385.         'title' => '',
  386.         'ad' => get_template_directory_uri()."/images/defaults/banner_600.jpg",
  387.         'link' => 'http://www.towfiqi.com',
  388.         );
  389.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  390.  
  391.         <!-- Widget Title: Text Input -->
  392.         <p>
  393.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  394.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  395.         </p>
  396.  
  397.         <!-- Ad image url: Text Input -->
  398.         <p>
  399.             <label for="<?php echo $this->get_field_id( 'ad' ); ?>"><?php _e('Ad image url:', 'Triton') ?></label>
  400.             <input class="widefat" id="<?php echo $this->get_field_id( 'ad' ); ?>" name="<?php echo $this->get_field_name( 'ad' ); ?>" value="<?php echo $instance['ad']; ?>" />
  401.         </p>
  402.        
  403.         <!-- Ad link url: Text Input -->
  404.         <p>
  405.             <label for="<?php echo $this->get_field_id( 'link' ); ?>"><?php _e('Ad link url:', 'Triton') ?></label>
  406.             <input class="widefat" id="<?php echo $this->get_field_id( 'link' ); ?>" name="<?php echo $this->get_field_name( 'link' ); ?>" value="<?php echo $instance['link']; ?>" />
  407.         </p>
  408.        
  409.     <?php
  410.     }
  411.  
  412. }
  413.  
  414. /* ---------------------------- */
  415. /* -------- Popular Posts Widget -------- */
  416. /* ---------------------------- */
  417. add_action( 'widgets_init', 'trt_pop_widgets' );
  418.  
  419. /*
  420.  * Register widget.
  421.  */
  422. function trt_pop_widgets() {
  423.     register_widget( 'trt_pop_Widget' );
  424. }
  425.  
  426. /*
  427.  * Widget class.
  428.  */
  429. class trt_pop_widget extends WP_Widget {
  430.  
  431.     /* ---------------------------- */
  432.     /* -------- Widget setup -------- */
  433.     /* ---------------------------- */
  434.    
  435.     function trt_pop_Widget() {
  436.    
  437.         /* Widget settings */
  438.         $widget_ops = array( 'classname' => 'trt_pop_widget', 'description' => __('A Triton widget that displays the most popular posts of the site, Based on the comments count ', 'Triton') );
  439.  
  440.         /* Widget control settings */
  441.         //$control_ops = array( 'width' => 160, 'height' => 600, 'id_base' => 'trt_pop_widget' );
  442.  
  443.         /* Create the widget */
  444.         $this->WP_Widget( 'trt_pop_widget', __('Popular Posts Widget', 'Triton'), $widget_ops );
  445.     }
  446.  
  447.     /* ---------------------------- */
  448.     /* ------- Display Widget -------- */
  449.     /* ---------------------------- */
  450.    
  451.     function widget( $args, $instance ) {
  452.         extract( $args );
  453.  
  454.         /* Our variables from the widget settings. */
  455.         $title = apply_filters('widget_title', $instance['title'] );
  456.         $num = $instance['num'];
  457.  
  458.         /* Before widget (defined by themes). */
  459.         echo $before_widget;
  460.  
  461.         /* Display the widget title if one was input (before and after defined by themes). */
  462.         if ( $title )
  463.             echo $before_title . $title . $after_title;
  464.            
  465.         /* Display a containing div */
  466.         echo '<div class="trt_pop">';
  467.  
  468.         /* Display Posts */
  469.         if ( $num )
  470.         $popular = new WP_Query('orderby=comment_count&posts_per_page=' . $num);
  471.        
  472.         echo '<ul>';
  473.         while ($popular->have_posts()) : $popular->the_post();
  474.         echo '<li>';
  475.         echo '<a class="trt_wgt_thumb" href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title() . '">';
  476.         if ( has_post_thumbnail() ) :
  477.         echo ''. the_post_thumbnail('thumbnail') . '';
  478.         elseif($photo = trt_get_images('numberposts=1', true)):
  479.         echo ''. wp_get_attachment_image($photo[0]->ID , $size='thumbnail') . '';
  480.         else :
  481.         echo '<img src="'.get_template_directory_uri().'/images/blank_img2.png" alt="'.get_the_title().'" class="thumbnail"/>';
  482.         endif;
  483.         echo '</a>';
  484.         echo '<div class="widget_content">';
  485.         echo '<a class="trt_wgt_tt" href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' ;
  486.         echo ''. trt_excerpt('trt_excerptlength_index', 'trt_excerptmore') . '';
  487.         echo '</div>';
  488.         echo '</li>';
  489.    
  490.         endwhile;
  491.        
  492.         echo '</ul>';
  493.            
  494.         echo '</div>';
  495.  
  496.         /* After widget (defined by themes). */
  497.         echo $after_widget;
  498.     }
  499.  
  500.     /* ---------------------------- */
  501.     /* ------- Update Widget -------- */
  502.     /* ---------------------------- */
  503.    
  504.     function update( $new_instance, $old_instance ) {
  505.         $instance = $old_instance;
  506.  
  507.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  508.         $instance['title'] = strip_tags( $new_instance['title'] );
  509.  
  510.         /* No need to strip tags */
  511.         $instance['num'] = $new_instance['num'];
  512.  
  513.         return $instance;
  514.     }
  515.    
  516.     /* ---------------------------- */
  517.     /* ------- Widget Settings ------- */
  518.     /* ---------------------------- */
  519.    
  520.     /**
  521.      * Displays the widget settings controls on the widget panel.
  522.      * Make use of the get_field_id() and get_field_name() function
  523.      * when creating your form elements. This handles the confusing stuff.
  524.      */
  525.    
  526.     function form( $instance ) {
  527.    
  528.         /* Set up some default widget settings. */
  529.         $defaults = array(
  530.         'title' => '',
  531.         'num' => 3,
  532.         );
  533.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  534.  
  535.         <!-- Widget Title: Text Input -->
  536.         <p>
  537.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  538.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  539.         </p>
  540.  
  541.         <!-- Number of Posts: Text Input -->
  542.         <p>
  543.             <label for="<?php echo $this->get_field_id( 'num' ); ?>"><?php _e('Number of Posts:', 'Triton') ?></label>
  544.             <input class="widefat" id="<?php echo $this->get_field_id( 'num' ); ?>" name="<?php echo $this->get_field_name( 'num' ); ?>" value="<?php echo $instance['num']; ?>" />
  545.         </p>
  546.        
  547.        
  548.     <?php
  549.     }
  550.  
  551. }
  552.  
  553.  
  554. /* ---------------------------- */
  555. /* -------- Random Posts Widget -------- */
  556. /* ---------------------------- */
  557.  
  558. add_action( 'widgets_init', 'trt_rand_widgets' );
  559.  
  560. /*
  561.  * Register widget.
  562.  */
  563. function trt_rand_widgets() {
  564.     register_widget( 'trt_rand_Widget' );
  565. }
  566.  
  567. /*
  568.  * Widget class.
  569.  */
  570. class trt_rand_widget extends WP_Widget {
  571.  
  572.     /* ---------------------------- */
  573.     /* -------- Widget setup -------- */
  574.     /* ---------------------------- */
  575.    
  576.     function trt_rand_Widget() {
  577.    
  578.         /* Widget settings */
  579.         $widget_ops = array( 'classname' => 'trt_rand_widget', 'description' => __('A Triton widget that displays the random posts of the site', 'Triton') );
  580.  
  581.         /* Widget control settings */
  582.         //$control_ops = array( 'width' => 160, 'height' => 600, 'id_base' => 'trt_rand_widget' );
  583.  
  584.         /* Create the widget */
  585.         $this->WP_Widget( 'trt_rand_widget', __('Random Posts Widget', 'Triton'), $widget_ops );
  586.     }
  587.  
  588.     /* ---------------------------- */
  589.     /* ------- Display Widget -------- */
  590.     /* ---------------------------- */
  591.    
  592.     function widget( $args, $instance ) {
  593.         extract( $args );
  594.  
  595.         /* Our variables from the widget settings. */
  596.         $title = apply_filters('widget_title', $instance['title'] );
  597.         $num = $instance['num'];
  598.  
  599.         /* Before widget (defined by themes). */
  600.         echo $before_widget;
  601.  
  602.         /* Display the widget title if one was input (before and after defined by themes). */
  603.         if ( $title )
  604.             echo $before_title . $title . $after_title;
  605.            
  606.         /* Display a containing div */
  607.         echo '<div class="trt_rand">';
  608.  
  609.         /* Display Posts */
  610.         if ( $num )
  611.         $popular = new WP_Query('orderby=rand&posts_per_page=' . $num);
  612.        
  613.         echo '<ul>';
  614.         while ($popular->have_posts()) : $popular->the_post();
  615.         echo '<li>';
  616.         echo '<a class="trt_wgt_thumb" href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title() . '">';
  617.         if ( has_post_thumbnail() ) :
  618.         echo ''. the_post_thumbnail('thumbnail') . '';
  619.         elseif($photo = trt_get_images('numberposts=1', true)):
  620.         echo ''. wp_get_attachment_image($photo[0]->ID , $size='thumbnail') . '';
  621.         else :
  622.         echo '<img src="'.get_template_directory_uri().'/images/blank_img2.png" alt="'.get_the_title().'" class="thumbnail"/>';
  623.         endif;
  624.         echo '</a>';
  625.         echo '<div class="widget_content">';
  626.         echo '<a class="trt_wgt_tt" href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' ;
  627.         echo ''. trt_excerpt('trt_excerptlength_index', 'trt_excerptmore') . '';
  628.         echo '</div>';
  629.         echo '</li>';
  630.    
  631.         endwhile;
  632.        
  633.         echo '</ul>';
  634.            
  635.         echo '</div>';
  636.  
  637.         /* After widget (defined by themes). */
  638.         echo $after_widget;
  639.     }
  640.  
  641.     /* ---------------------------- */
  642.     /* ------- Update Widget -------- */
  643.     /* ---------------------------- */
  644.    
  645.     function update( $new_instance, $old_instance ) {
  646.         $instance = $old_instance;
  647.  
  648.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  649.         $instance['title'] = strip_tags( $new_instance['title'] );
  650.  
  651.         /* No need to strip tags */
  652.         $instance['num'] = $new_instance['num'];
  653.  
  654.         return $instance;
  655.     }
  656.    
  657.     /* ---------------------------- */
  658.     /* ------- Widget Settings ------- */
  659.     /* ---------------------------- */
  660.    
  661.     /**
  662.      * Displays the widget settings controls on the widget panel.
  663.      * Make use of the get_field_id() and get_field_name() function
  664.      * when creating your form elements. This handles the confusing stuff.
  665.      */
  666.    
  667.     function form( $instance ) {
  668.    
  669.         /* Set up some default widget settings. */
  670.         $defaults = array(
  671.         'title' => '',
  672.         'num' => 3,
  673.         );
  674.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  675.  
  676.         <!-- Widget Title: Text Input -->
  677.         <p>
  678.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  679.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  680.         </p>
  681.  
  682.         <!-- Number of Posts: Text Input -->
  683.         <p>
  684.             <label for="<?php echo $this->get_field_id( 'num' ); ?>"><?php _e('Number of Posts:', 'Triton') ?></label>
  685.             <input class="widefat" id="<?php echo $this->get_field_id( 'num' ); ?>" name="<?php echo $this->get_field_name( 'num' ); ?>" value="<?php echo $instance['num']; ?>" />
  686.         </p>
  687.        
  688.        
  689.     <?php
  690.     }
  691.  
  692. }
  693.  
  694. /*
  695.     /* ---------------------------- */
  696.     /* -------- Featured Posts Widget -------- */
  697.     /* ---------------------------- */
  698. add_action( 'widgets_init', 'trt_feat_widgets' );
  699.  
  700. /*
  701.  * Register widget.
  702.  */
  703. function trt_feat_widgets() {
  704.     register_widget( 'trt_feat_Widget' );
  705. }
  706.  
  707. /*
  708.  * Widget class.
  709.  */
  710. class trt_feat_widget extends WP_Widget {
  711.  
  712.     /* ---------------------------- */
  713.     /* -------- Widget setup -------- */
  714.     /* ---------------------------- */
  715.    
  716.     function trt_feat_Widget() {
  717.    
  718.         /* Widget settings */
  719.         $widget_ops = array( 'classname' => 'trt_feat_widget', 'description' => __('A Triton widget that displays the featured posts from your selected category', 'Triton') );
  720.  
  721.         /* Widget control settings */
  722.         //$control_ops = array( 'width' => 160, 'height' => 600, 'id_base' => 'trt_feat_widget' );
  723.  
  724.         /* Create the widget */
  725.         $this->WP_Widget( 'trt_feat_widget', __('Featured Posts Widget', 'Triton'), $widget_ops );
  726.     }
  727.  
  728.     /* ---------------------------- */
  729.     /* ------- Display Widget -------- */
  730.     /* ---------------------------- */
  731.    
  732.     function widget( $args, $instance ) {
  733.         extract( $args );
  734.  
  735.         /* Our variables from the widget settings. */
  736.         $title = apply_filters('widget_title', $instance['title'] );
  737.         $num = $instance['num'];
  738.         $cat = $instance['cat'];
  739.  
  740.         /* Before widget (defined by themes). */
  741.         echo $before_widget;
  742.  
  743.         /* Display the widget title if one was input (before and after defined by themes). */
  744.         if ( $title )
  745.             echo $before_title . $title . $after_title;
  746.            
  747.         /* Display a containing div */
  748.         echo '<div class="trt_feat">';
  749.  
  750.         /* Display Posts */
  751.         if ( $num )
  752.         $popular = new WP_Query('cat=' . $cat .' &posts_per_page=' . $num);
  753.         echo '<ul>';
  754.         while ($popular->have_posts()) : $popular->the_post();
  755.         echo '<li>';
  756.         echo '<a class="trt_wgt_thumb" href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title() . '">';
  757.         if ( has_post_thumbnail() ) :
  758.         echo ''. the_post_thumbnail('thumbnail') . '';
  759.         elseif($photo = trt_get_images('numberposts=1', true)):
  760.         echo ''. wp_get_attachment_image($photo[0]->ID , $size='thumbnail') . '';
  761.         else :
  762.         echo '<img src="'.get_template_directory_uri().'/images/blank_img2.png" alt="'.get_the_title().'" class="thumbnail"/>';
  763.         endif;
  764.         echo '</a>';
  765.         echo '<div class="widget_content">';
  766.         echo '<a class="trt_wgt_tt" href="' . get_permalink(get_the_ID()) . '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' ;
  767.         echo ''. trt_excerpt('trt_excerptlength_index', 'trt_excerptmore') . '';
  768.         echo '</div>';
  769.         echo '</li>';
  770.    
  771.         endwhile;
  772.        
  773.         echo '</ul>';
  774.            
  775.         echo '</div>';
  776.  
  777.         /* After widget (defined by themes). */
  778.         echo $after_widget;
  779.     }
  780.  
  781.     /* ---------------------------- */
  782.     /* ------- Update Widget -------- */
  783.     /* ---------------------------- */
  784.    
  785.     function update( $new_instance, $old_instance ) {
  786.         $instance = $old_instance;
  787.  
  788.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  789.         $instance['title'] = strip_tags( $new_instance['title'] );
  790.  
  791.         /* No need to strip tags */
  792.         $instance['num'] = $new_instance['num'];
  793.         $instance['cat'] = $new_instance['cat'];
  794.  
  795.         return $instance;
  796.     }
  797.    
  798.     /* ---------------------------- */
  799.     /* ------- Widget Settings ------- */
  800.     /* ---------------------------- */
  801.    
  802.     /**
  803.      * Displays the widget settings controls on the widget panel.
  804.      * Make use of the get_field_id() and get_field_name() function
  805.      * when creating your form elements. This handles the confusing stuff.
  806.      */
  807.    
  808.     function form( $instance ) {
  809.    
  810.         /* Set up some default widget settings. */
  811.         $defaults = array(
  812.         'title' => '',
  813.         'num' => 3,
  814.         'cat' => 0,
  815.         );
  816.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  817.  
  818.         <!-- Widget Title: Text Input -->
  819.         <p>
  820.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  821.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  822.         </p>
  823.        
  824.         <!-- Category of Posts: Text Input -->
  825.         <p>
  826.             <label for="<?php echo $this->get_field_id( 'cat' ); ?>"><?php _e('Category of Posts:', 'Triton') ?></label>
  827.             <input class="widefat" id="<?php echo $this->get_field_id( 'cat' ); ?>" name="<?php echo $this->get_field_name( 'cat' ); ?>" value="<?php echo $instance['cat']; ?>" />
  828.         </p>
  829.  
  830.         <!-- Number of Posts: Text Input -->
  831.         <p>
  832.             <label for="<?php echo $this->get_field_id( 'num' ); ?>"><?php _e('Number of Posts:', 'Triton') ?></label>
  833.             <input class="widefat" id="<?php echo $this->get_field_id( 'num' ); ?>" name="<?php echo $this->get_field_name( 'num' ); ?>" value="<?php echo $instance['num']; ?>" />
  834.         </p>
  835.        
  836.        
  837.     <?php
  838.     }
  839.  
  840. }
  841.  
  842. /*
  843.     /* ---------------------------- */
  844.     /* -------- Twitter Feeds Widget -------- */
  845.     /* ---------------------------- */
  846. add_action( 'widgets_init', 'trt_twt_widgets' );
  847.  
  848. /*
  849.  * Register widget.
  850.  */
  851. function trt_twt_widgets() {
  852.     register_widget( 'trt_twt_Widget' );
  853. }
  854.  
  855. /*
  856.  * Widget class.
  857.  */
  858. class trt_twt_widget extends WP_Widget {
  859.  
  860.     /* ---------------------------- */
  861.     /* -------- Widget setup -------- */
  862.     /* ---------------------------- */
  863.    
  864.     function trt_twt_Widget() {
  865.    
  866.         /* Widget settings */
  867.         $widget_ops = array( 'classname' => 'trt_twt_widget', 'description' => __('A Triton widget that displays the Twitter Feeds from your twitter account', 'Triton') );
  868.  
  869.         /* Widget control settings */
  870.         /* Create the widget */
  871.         $this->WP_Widget( 'trt_twt_widget', __('Twitter Feeds Widget', 'Triton'), $widget_ops );
  872.     }
  873.  
  874.     /* ---------------------------- */
  875.     /* ------- Display Widget -------- */
  876.     /* ---------------------------- */
  877.    
  878.     function widget( $args, $instance ) {
  879.         extract( $args );
  880.  
  881.         /* Our variables from the widget settings. */
  882.         $title = apply_filters('widget_title', $instance['title'] );
  883.         $count = $instance['count'];
  884.         $cat = $instance['cat'];
  885.  
  886.         /* Before widget (defined by themes). */
  887.         echo $before_widget;
  888.  
  889.         /* Display the widget title if one was input (before and after defined by themes). */
  890.         if ( $title )
  891.             echo $before_title . $title . $after_title;
  892.            
  893.         /* Display a containing div */
  894.         echo '<div class="trt_twitter"><ul id="twitter_update_list"></ul><script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script><script type="text/javascript" src="http://twitter.com/statuses/user_timeline/' . $cat . '.json?callback=twitterCallback2&amp;count=' . $count . '"></script>';
  895.         echo '</div>';
  896.  
  897.         /* After widget (defined by themes). */
  898.         echo $after_widget;
  899.     }
  900.  
  901.     /* ---------------------------- */
  902.     /* ------- Update Widget -------- */
  903.     /* ---------------------------- */
  904.    
  905.     function update( $new_instance, $old_instance ) {
  906.         $instance = $old_instance;
  907.  
  908.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  909.         $instance['title'] = strip_tags( $new_instance['title'] );
  910.  
  911.         /* No need to strip tags */
  912.         $instance['count'] = $new_instance['count'];
  913.         $instance['cat'] = $new_instance['cat'];
  914.  
  915.         return $instance;
  916.     }
  917.    
  918.     /* ---------------------------- */
  919.     /* ------- Widget Settings ------- */
  920.     /* ---------------------------- */
  921.    
  922.     /**
  923.      * Displays the widget settings controls on the widget panel.
  924.      * Make use of the get_field_id() and get_field_name() function
  925.      * when creating your form elements. This handles the confusing stuff.
  926.      */
  927.    
  928.     function form( $instance ) {
  929.    
  930.         /* Set up some default widget settings. */
  931.         $defaults = array(
  932.         'title' => '',
  933.         'count' => '5',
  934.         'cat' => 'towfiqi',
  935.         );
  936.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  937.  
  938.         <!-- Widget Title: Text Input -->
  939.         <p>
  940.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  941.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  942.         </p>
  943.        
  944.         <!-- Category of Posts: Text Input -->
  945.         <p>
  946.             <label for="<?php echo $this->get_field_id( 'cat' ); ?>"><?php _e('Account ID:', 'Triton') ?></label>
  947.             <input class="widefat" id="<?php echo $this->get_field_id( 'cat' ); ?>" name="<?php echo $this->get_field_name( 'cat' ); ?>" value="<?php echo $instance['cat']; ?>" />
  948.         </p>
  949.  
  950.         <!-- Number of Posts: Text Input -->
  951.         <p>
  952.             <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e('Number of Posts:', 'Triton') ?></label>
  953.             <input class="widefat" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" value="<?php echo $instance['count']; ?>" />
  954.         </p>
  955.        
  956.        
  957.     <?php
  958.     }
  959.  
  960. }
  961.  
  962. /*
  963.     /* ---------------------------- */
  964.     /* -------- Flickr Photostream Widget -------- */
  965.     /* ---------------------------- */
  966. add_action( 'widgets_init', 'trt_flckr_widgets' );
  967.  
  968. /*
  969.  * Register widget.
  970.  */
  971. function trt_flckr_widgets() {
  972.     register_widget( 'trt_flckr_Widget' );
  973. }
  974.  
  975. /*
  976.  * Widget class.
  977.  */
  978. class trt_flckr_widget extends WP_Widget {
  979.  
  980.     /* ---------------------------- */
  981.     /* -------- Widget setup -------- */
  982.     /* ---------------------------- */
  983.    
  984.     function trt_flckr_Widget() {
  985.    
  986.         /* Widget settings */
  987.         $widget_ops = array( 'classname' => 'trt_flckr_widget', 'description' => __('A Triton widget that displays Flickr image stream from your Flickr account', 'Triton') );
  988.  
  989.         /* Widget control settings */
  990.         /* Create the widget */
  991.         $this->WP_Widget( 'trt_flckr_widget', __('Flickr Photostream Widget', 'Triton'), $widget_ops );
  992.     }
  993.  
  994.     /* ---------------------------- */
  995.     /* ------- Display Widget -------- */
  996.     /* ---------------------------- */
  997.    
  998.     function widget( $args, $instance ) {
  999.         extract( $args );
  1000.  
  1001.         /* Our variables from the widget settings. */
  1002.         $title = apply_filters('widget_title', $instance['title'] );
  1003.         $flickrID = $instance['flickrID'];
  1004.         $postcount = $instance['postcount'];
  1005.         $type = $instance['type'];
  1006.         $display = $instance['display'];
  1007.  
  1008.         /* Before widget (defined by themes). */
  1009.         echo $before_widget;
  1010.  
  1011.         /* Display the widget title if one was input (before and after defined by themes). */
  1012.         if ( $title )
  1013.             echo $before_title . $title . $after_title;
  1014.  
  1015.         /* Display Flickr Photos */
  1016.          ?>
  1017.            
  1018.             <div id="flickr_badge_wrapper" class="clearfix">
  1019.                 <script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=<?php echo $postcount ?>&amp;display=<?php echo $display ?>&amp;size=s&amp;layout=x&amp;source=<?php echo $type ?>&amp;<?php echo $type ?>=<?php echo $flickrID ?>"></script>
  1020.             </div>
  1021.        
  1022.         <?php
  1023.  
  1024.         /* After widget (defined by themes). */
  1025.         echo $after_widget;
  1026.     }
  1027.  
  1028.     /* ---------------------------- */
  1029.     /* ------- Update Widget -------- */
  1030.     /* ---------------------------- */
  1031.    
  1032.     function update( $new_instance, $old_instance ) {
  1033.         $instance = $old_instance;
  1034.  
  1035.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  1036.         $instance['title'] = strip_tags( $new_instance['title'] );
  1037.         $instance['flickrID'] = strip_tags( $new_instance['flickrID'] );
  1038.         $instance['postcount'] = $new_instance['postcount'];
  1039.         $instance['type'] = $new_instance['type'];
  1040.         $instance['display'] = $new_instance['display'];
  1041.  
  1042.         /* No need to strip tags for.. */
  1043.  
  1044.         return $instance;
  1045.     }
  1046.    
  1047.     /* ---------------------------- */
  1048.     /* ------- Widget Settings ------- */
  1049.     /* ---------------------------- */
  1050.    
  1051.     /**
  1052.      * Displays the widget settings controls on the widget panel.
  1053.      * Make use of the get_field_id() and get_field_name() function
  1054.      * when creating your form elements. This handles the confusing stuff.
  1055.      */
  1056.      
  1057.     function form( $instance ) {
  1058.  
  1059.         /* Set up some default widget settings. */
  1060.         $defaults = array(
  1061.         'title' => 'My Photostream',
  1062.         'flickrID' => '82938015@N00',
  1063.         'postcount' => '9',
  1064.         'type' => 'user',
  1065.         'display' => 'random',
  1066.         );
  1067.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  1068.  
  1069.         <!-- Widget Title: Text Input -->
  1070.         <p>
  1071.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  1072.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  1073.         </p>
  1074.  
  1075.         <!-- Flickr ID: Text Input -->
  1076.         <p>
  1077.             <label for="<?php echo $this->get_field_id( 'flickrID' ); ?>"><?php _e('Flickr ID:', 'Triton') ?> (<a href="http://idgettr.com/">idGettr</a>)</label>
  1078.             <input class="widefat" id="<?php echo $this->get_field_id( 'flickrID' ); ?>" name="<?php echo $this->get_field_name( 'flickrID' ); ?>" value="<?php echo $instance['flickrID']; ?>" />
  1079.         </p>
  1080.        
  1081.         <!-- Postcount: Text Input -->
  1082.         <p>
  1083.             <label for="<?php echo $this->get_field_id( 'postcount' ); ?>"><?php _e('Number of Photos:', 'Triton') ?></label>
  1084.             <select id="<?php echo $this->get_field_id( 'postcount' ); ?>" name="<?php echo $this->get_field_name( 'postcount' ); ?>" class="widefat">
  1085.                 <option <?php if ( '3' == $instance['postcount'] ) echo 'selected="selected"'; ?>>3</option>
  1086.                 <option <?php if ( '6' == $instance['postcount'] ) echo 'selected="selected"'; ?>>6</option>
  1087.                 <option <?php if ( '9' == $instance['postcount'] ) echo 'selected="selected"'; ?>>9</option>
  1088.             </select>
  1089.         </p>
  1090.        
  1091.         <!-- Type: Select Box -->
  1092.         <p>
  1093.             <label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php _e('Type (user or group):', 'Triton') ?></label>
  1094.             <select id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" class="widefat">
  1095.                 <option <?php if ( 'user' == $instance['type'] ) echo 'selected="selected"'; ?>>user</option>
  1096.                 <option <?php if ( 'group' == $instance['type'] ) echo 'selected="selected"'; ?>>group</option>
  1097.             </select>
  1098.         </p>
  1099.        
  1100.         <!-- Display: Select Box -->
  1101.         <p>
  1102.             <label for="<?php echo $this->get_field_id( 'display' ); ?>"><?php _e('Display (random or latest):', 'Triton') ?></label>
  1103.             <select id="<?php echo $this->get_field_id( 'display' ); ?>" name="<?php echo $this->get_field_name( 'display' ); ?>" class="widefat">
  1104.                 <option <?php if ( 'random' == $instance['display'] ) echo 'selected="selected"'; ?>>random</option>
  1105.                 <option <?php if ( 'latest' == $instance['display'] ) echo 'selected="selected"'; ?>>latest</option>
  1106.             </select>
  1107.         </p>
  1108.        
  1109.     <?php
  1110.     }
  1111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement