Widget to work in conjunction with existing plugin
-
In converting my portfolio site to a wp site, I came across the wp-portfolio plugin which is working perfectly. In the meanwhile I had come up with the nifty idea that I could create a widget (my first one!) that could display a given number of links for recently launched projects. The front end is currently displaying the most recent record (as it’s supposed to), however, I thought in the admin I could give myself an opportunity to update the sort and limit. The form displays just fine for the widget, but when I click on save nothing happens. Furthermore, after clicking save and then refreshing the front end it is still displaying the most recent project.
I’d love to share the link with you but I’m currently working on this locally with XAMPP, but if you require more information just let me know. I’ve read almost every page in the wp plugin docs and I’ve done approx 30 googles for tutorials and examples. I’ve just about pulled out all my hair and any help would be greatly appreciated.
<?php /* * Plugin Name: Portfolio Widget * Version: 1.0 * Plugin URI: * Description: Widget designed specifically for BernadetteMcCarthy.com to work in conjunction with the WP-Portfolio plugin. * Author: Bernadette McCarthy * Author URI: http://bernadettemccarthy.com/ */ class bdm_portfolio_widget extends WP_Widget { function bdm_portfolio_widget() { parent::WP_Widget(false, $name='Recent Projects Widget'); } //close bdm_portfolio_widget() function widget ($args, $instance){ global $wpdb; extract($args); $sort = $this->update($instance['sort']); $limit = $this->update($instance['limit']); echo $before_widget; echo $before_title.'Recently Launched Projects'.$after_title; echo '<ul id="recently-launched">'; $results = $wpdb->get_results("SELECT * FROM wp_wpportfolio_websites ORDER BY siteid DESC LIMIT 0,1",ARRAY_A); foreach ($results AS $result) { $siteid = $result['siteid']; $sitename = $result['sitename']; $siteurl = $result['siteurl']; echo '<li><a href="'.$siteurl.'" target="_blank">'.$sitename.'</a></li>'; } echo '</ul>'; echo $after_widget; } //close widget() function update ($new_instance,$old_instance){ $instance = $old_instance; $instance['sort'] = $new_instance['sort']; $instance['limit'] = $new_instance['limit']; return $instance; } //close update() function form ($instance){ $instance = wp_parse_args((array) $instance, array('sort'=>'siteid','limit'=>1)); $sort = htmlspecialchars($instance['sort']); $limit = htmlspecialchars($instance['limit']); echo '<p style="text-align:left;"><label for="'.$this->get_field_name('sort').'">'.__('Sort By: ').'<select name="'.$this->get_field_name('sort').'" id="'.$this->get_field_id('sort').'"><option value="siteid">Site ID</option><option value="sitename">Site Name</option><option value="siteurl">Site URL</option></select></label></p>'; echo '<p style="text-align:left;"><label for="'.$this->get_field_name('limit').'">'.__('Limit To: ').'<input name="'.$this->get_field_name('limit').'" id="'.$this->get_field_id('limit').'" size="5" /></label></p>'; } //close form() } //close class function bdm_portfolio_widgetInit() { register_widget('bdm_portfolio_widget'); } //close bdm_portfolio_widgetInit() add_action('widgets_init','bdm_portfolio_widgetInit'); ?>
The topic ‘Widget to work in conjunction with existing plugin’ is closed to new replies.