Implementing the widget display function
For all of the widget creation work that we have done so far, our new creation does not display any content on the website yet. When displaying an area that contains widgets, WordPress tries to call a method named widget
for each user-selected widget to output the desired content to the browser.
This recipe shows how to implement a widget
method to display a list of recent book reviews when the widget is instantiated in a sidebar.
Getting ready
You should have already followed the Validating configuration options recipe to have a starting point for this recipe. Alternatively, you can get the resulting code (Chapter 10/ch10-book-review-widget/ch10-book-review-widget-v3.php
) from the code bundle and rename the file as ch10-book-review-widget.php
.
How to do it...
- Navigate to the WordPress plugin directory of your development installation.
- Navigate to the
ch10-book-review-widget
directory and editch10-book-review-widget.php
. - Find the
Book_Reviews
class and...