Custom Widget Code
-
I’ve got multiple tabs open with tutorials for creating a custom WP widget and I’m confused since they are all saying slighting different things.
I’ve created my plugin and it shows up in the plugin list (good so far).
Where I’m challenged is in adding the code to actually create the widget and what order things go in since each tutorial is doing it differently and I’d like to start out with Best Practices.
This where I am so far and I’m already stuck because I have questions….
<?php /* Plugin Name: Fuller Donation Widgets Description: Donation channel widgets Author: Sandy Fischler Version: 1 */ /* Start Adding Functions Below this Line */ class fuller_of_openstrap_donation_page_one extends WP_Widget { function fuller_of_openstrap_donation_page_one() { parent::__construct(false, $name = __('Fuller Donation Widget One', 'fuller_of_openstrap_donation_page_one') ); }Questions:
1) Do I state the class first or register the widget first? I see it done both ways. One tutorial starts out with register widget and another has it much lower in the code.
2) In the WP codex they use parent::__construct, in one tutorial they use parent::WP_Widget which is correct?
Thanks!
-
That was it – I had some white space at the end of my functions.php file.
You are such a lifesaver….thank you, thank you, thank you.
Sure, no problem. If all of your initial questions are resolved, too, go ahead and mark this topic as resolved.
For the record, here is how our spiffy new widgets came out with Ryan’s awesome help!
Did you guys ever find out how to get the form inputs to stay displayed when you drag and drop the widget into the sidebar? is there a way to trigger the save button on the drop action?
The topic ‘Custom Widget Code’ is closed to new replies.