| Server IP : 37.27.51.148 / Your IP : 37.27.51.148 Web Server : nginx/1.14.1 System : Linux libra 4.18.0-553.51.1.el8_10.x86_64 #1 SMP Wed Apr 30 20:24:04 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.31 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/themes/zodiac22/inc/widgets/ |
Upload File : |
<?php
class RecentPosts extends WP_Widget
{
function __construct()
{
parent::__construct(
'zodiac_recent_posts', // Base ID
'Zodiac Recent Posts Widget', // Name
['description' => __('Displays recent posts with thumbnails', 'text_domain')] // Args
);
}
function widget($args, $instance)
{
?>
<div class="p-3">
<?php
if (!empty($instance['title'])) {
?><h4 class="text-muted mb-2"><?php echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];?></h4><?php
}
$recent_posts = new WP_Query([
'posts_per_page' => !empty($instance['number']) ? $instance['number'] : 5,
'post_status' => 'publish',
]);
if ($recent_posts->have_posts()) : ?>
<section class="">
<?php while ($recent_posts->have_posts()) : $recent_posts->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="row mb-3 py-3 text-decoration-none">
<div class="col-md-8">
<h3 class="h6 font-weight-normal"><?php the_title(); ?></h3>
<time class="text-muted small d-none d-md-block"><?php echo get_the_date('F jS, Y'); ?></time>
</div>
<div class="col-md-4">
<img src="<?php echo esc_url(get_the_post_thumbnail_url(get_the_ID(), 'blog_featured_regular')); ?>"
class="img-fluid" alt="<?php the_title_attribute(); ?>"/>
</div>
</a>
<?php endwhile; ?>
</section>
<?php
endif;
?>
</div>
<?php
wp_reset_postdata();
}
function update($new_instance, $old_instance)
{
$instance = [];
$instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
$instance['number'] = (!empty($new_instance['number'])) ? strip_tags($new_instance['number']) : '';
return $instance;
}
function form($instance)
{
$title = !empty($instance['title']) ? $instance['title'] : __('New title', 'text_domain');
$number = !empty($instance['number']) ? $instance['number'] : 5;
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
name="<?php echo $this->get_field_name('title'); ?>" type="text"
value="<?php echo esc_attr($title); ?>"/>
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('number'); ?>"
name="<?php echo $this->get_field_name('number'); ?>" type="number"
value="<?php echo esc_attr($number); ?>" min="1"/>
</p>
<?php
}
} // end class RecentPosts
function load_recent_posts_widget()
{
register_widget('RecentPosts');
}
add_action('widgets_init', 'load_recent_posts_widget');