creating a function in a widget
-
So I think the function has to go inside the “widget” function of the widget class, which is what I have done here.
function widget($args, $instance) { function getstockstats ($stocksymbol) { include_once('class.yahoostock.php'); $objYahooStock = new YahooStock; $objYahooStock->addFormat("snl1d1t1cvc1p2"); $objYahooStock->addStock('IWM'); $i = 0; foreach( $objYahooStock->getQuotes() as $code => $stock) : $i++; echo '<div class=/"item'; echo ($stock[7] > 0) ? 'green' : 'red'; echo '/"> '; echo '<span style=/"color:black; font-weight:bold;/">'; echo $stock[0]; echo '</span>'; echo '<span style=/"color:black;/">'; echo $stock[2]; echo '</span>'; echo '<strong>'; echo $stock[7]; echo '</strong'; echo str_replace('"', '', $stock[8]); echo '</div>'; endforeach; return $stock; } extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) echo $before_title . $title . $after_title; // WIDGET CODICE VA QUA echo getstockstats("aapl"); // DOPO WIDGET CODICE echo $after_widget; }
I want to supply the getstockstats function with a ticker, and have it spit out an array containing information about the ticker.
Currently, it doesn’t do anything, I’m not sure what I’m doing wrong here, does anyone have any tips?
- The topic ‘creating a function in a widget’ is closed to new replies.