News Feed Widget
About the widget
The News Feed Widget can be used anywhere in the website, and bring the latest news according to filtering selection. Common uses are in the sidebars of the website.
Data here always come client-side due to caching issues , in order to always have fresh posts. The endpoint that is being used is get_site_url() . '/news-feed/' . $widget_key . '/'
and the segment of the widget key is sent so it can be determined what dataset should be returned
It contains the following feature:
- Select post by categories to include
- Select post by categories to exclude
- Select post types to show
- Change link and title in footer of widget
- Add tab label
- Activate a second tab to toggle between with the same features as the first one
Enable Widget
In order for the News Feed Widget widget to appear in the Widgets list (Appearance -> Widgets) we need to enable it.
Widget Override
If you need to override the widget in the child theme, you must inherit the parent widget of the parent theme. Inside your child theme folder (usually in wp-content/themes/nx-theme-child), create a relevant folder structure as the parent theme wp-content/themes/nx-theme-child/widgets. Create a php file that inherits the parent widget as follows
class News_Feed_Widget_Child extends News_Feed_Widget { ... widget stuff }
Next step is to replace the parent widget and yo can do so as follows in functions.php
function replace_parent_widget() { if ( class_exists('News_Feed_Widget') ) { unregister_widget('News_Feed_Widget'); require_once get_theme_file_path('/widgets/News_Feed_Widget_Child.php'); register_widget('News_Feed_Widget_Child'); } } add_action('widgets_init', 'replace_parent_widget', 15);