class My_Widget extends WP_Widget { function __construct() { parent::__construct( 'my_widget', 'My Widget', array( 'description' => 'Displays a message' ) ); } public function widget( $args, $instance ) { echo 'Hello, World!
'; } } function register_my_widget() { register_widget( 'My_Widget' ); } add_action( 'widgets_init', 'register_my_widget' );
class Recent_Posts_Widget extends WP_Widget { function __construct() { parent::__construct( 'recent_posts_widget', 'Recent Posts Widget', array( 'description' => 'Displays a list of recent posts' ) ); } public function widget( $args, $instance ) { echo 'Recent Posts
'; $query_args = array( 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'desc' ); $recent_posts = new WP_Query( $query_args ); if ( $recent_posts->have_posts() ) { echo '