Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 11th, 2012  |  syntax: None  |  size: 1.39 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP functions within WordPress widget function/class
  2. add_action("widgets_init", array('LMC_countdown', 'register'));
  3.  
  4. class LMC_countdown extends WP_Widget {
  5.  
  6.   function control(){
  7.     echo "This widget doesn't need a control panel in WordPress right now.";
  8.     # In all likelihood, that'll be a separate issue for later. :)
  9.   }
  10.   function widget($args){
  11.     echo $args['before_widget'];
  12.       # //////////////////// BEGIN MAIN WIDGET FUNCTION ////////////////////
  13.       $year = date("Y",$today);
  14.       echo "<div id="sidebar-countdown">";
  15.         /* ...
  16.            quite a bit of additional PHP logic here, but boils down to:
  17.         */
  18.         echo countdownTo(findEventStart($year));
  19.       echo "</div>";
  20.       # //////////////////// END MAIN WIDGET FUNCTION ////////////////////
  21.     echo $args['after_widget'];
  22.   }
  23.   function register(){
  24.     register_sidebar_widget('LMC Countdown', array('LMC_countdown', 'widget'));
  25.     register_widget_control('LMC Countdown', array('LMC_countdown', 'control'));
  26.   }
  27.  
  28. } # end class LMC_countdown
  29.        
  30. ...
  31.   }
  32.  
  33. } # end class LMC_countdown
  34.  
  35.  
  36. function countdownTo() {
  37.   ...
  38.        
  39. class LMC_countdown extends WP_Widget {
  40.   # private functions
  41.   private function countdownTo() {
  42.     ...
  43.   }
  44.   private function findEventStart($year) {
  45.     ...
  46.   }
  47.   ...
  48.   # wp widget functions
  49.   function widget($args){
  50.     ...
  51.     echo $this->countdownTo($this->findEventStart($year));
  52.     ...
  53.   }
  54.   ...
  55. }