
Untitled
By: a guest on
Jun 11th, 2012 | syntax:
None | size: 1.39 KB | hits: 8 | expires: Never
PHP functions within WordPress widget function/class
add_action("widgets_init", array('LMC_countdown', 'register'));
class LMC_countdown extends WP_Widget {
function control(){
echo "This widget doesn't need a control panel in WordPress right now.";
# In all likelihood, that'll be a separate issue for later. :)
}
function widget($args){
echo $args['before_widget'];
# //////////////////// BEGIN MAIN WIDGET FUNCTION ////////////////////
$year = date("Y",$today);
echo "<div id="sidebar-countdown">";
/* ...
quite a bit of additional PHP logic here, but boils down to:
*/
echo countdownTo(findEventStart($year));
echo "</div>";
# //////////////////// END MAIN WIDGET FUNCTION ////////////////////
echo $args['after_widget'];
}
function register(){
register_sidebar_widget('LMC Countdown', array('LMC_countdown', 'widget'));
register_widget_control('LMC Countdown', array('LMC_countdown', 'control'));
}
} # end class LMC_countdown
...
}
} # end class LMC_countdown
function countdownTo() {
...
class LMC_countdown extends WP_Widget {
# private functions
private function countdownTo() {
...
}
private function findEventStart($year) {
...
}
...
# wp widget functions
function widget($args){
...
echo $this->countdownTo($this->findEventStart($year));
...
}
...
}