If you want to be able to add the content into a widget, I would suggest duplicating that function I mentioned above (& renaming it), and then using it to create a simple shortcode that you can then use within the widget.
If you're not familiar with Shortcodes, then I would suggest having a look at this tutplus article on creating Shortcodes.