HEX
Server: nginx/1.27.1
System: Linux in-4 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64
User: ilikadirect (1186)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source
Upload Files
File: /storage/v6964/iskcon/public_html/wp-content/plugins/tow-widgets/widgets/custom/tow-recent-post.php
<?php
class tow_recentpost_widget extends WP_Widget {
  
	function __construct() {
		parent::__construct(
	  
		// Base ID
		'tow_recentpost', 
	  
		// Widget name
		__('Tow Recent Post', 'tow'), 
	  
		// Widget description
		array( 'description' => __( 'Sample widget based on tow theme', 'tow' ), ) 
		);
	}
  
	// Widget front-end
	  
	public function widget( $args, $instance ) {

		$title = apply_filters( 'widget_title', $instance['title'] );
		$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
		if ( ! $number )
			$number = 5;
		$aria_current = '';

		$tow_posts = array(
            'post_type'           => 'post',	
			'posts_per_page'      => $number,
			'post_status'         => 'publish',
			'no_found_rows'       => true,
            'order'               => 'DESC',
            'suppress_filters'  => 0
           
        );
        $tow_loop = new WP_Query( $tow_posts );

		echo $args['before_widget'];
		if ( ! empty( $title ) )
		echo $args['before_title'] . $title . $args['after_title']; ?>
		
		<style>
		   .blog_pg1r1 #recent-posts h6,.blog_pg1r1 #recent-posts h5 a{
		      color: #000000!important;
		   }
		</style>
		
	    <div class="row" id="recent-posts">
		    <?php
		    if($tow_loop->have_posts()){
	            while($tow_loop->have_posts()){
	                $tow_loop->the_post(); //print "------------".the_ID();?>
					
					
					 <div class="col-md-3 col-4 mb-4">
						   <div class="footer_1lil">
							   <div class="grid clearfix">
									<figure class="effect-jazz mb-0">
									<a href="<?php echo esc_url(get_the_permalink()) ?>">
									<?php
									    $thumbnail_id = get_post_thumbnail_id( get_the_ID() );
                                         if ( $thumbnail_id ) {
											$image_url = wp_get_attachment_image_src( $thumbnail_id, 'tow-360x240' ); // 'full' can be replaced with 'thumbnail', 'medium', etc.
											
											if ( $image_url ) {
												echo '<img src="' . esc_url( $image_url[0] ) . '" alt="Post Image" class="w-100">';
											} else {
												echo 'No image available.';
											}
										}
									?>
									<?php  //the_post_thumbnail('tow-360x240',array( 'class' => 'w-100')); ?>	</a>
									</figure>
								</div>
						   </div>
					  </div>
					  <div class="col-md-9 col-8">
						   <div class="footer_1lir">
							   <h6 class="font_13 text-white"><i class="fa fa-calendar col_oran me-1"></i> <?php echo get_the_date( 'M d, Y' );?></h6>
							   <h5 class="mb-0 fs-6"><a class="text-light a_tag" href="<?php echo esc_url(get_the_permalink()) ?>"><?php the_title(); ?></a></h5>
						   </div>
					  </div>
					
	               <?php
	                
	            }
	            wp_reset_postdata();
	        } ?>
	    </div> <?php    

		echo $args['after_widget'];

      
	}
          
	// Widget Backend 
	public function form( $instance ) {
			$title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
			$number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;		
		?>
		<p>
		  <label for="<?php echo esc_attr($this->get_field_id( 'title' )); ?>">
		    <?php _e( 'Title:','tow' ); ?>
		  </label>
		  <input class="widefat" id="<?php echo esc_attr($this->get_field_id( 'title' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" type="text" value="<?php echo esc_js($title); ?>" />
		</p>

		<p>
		  <label for="<?php echo esc_attr($this->get_field_id( 'number' )); ?>">
		    <?php _e( 'Number of posts to show:','tow' ); ?>
		  </label>
		  <input class="tiny-text" id="<?php echo esc_attr($this->get_field_id( 'number' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'number' )); ?>" type="number" step="1" min="1" value="<?php echo esc_js($number); ?>" size="3" />
		</p>
		<?php 
	}
      
	// Updating widget
	public function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['title'] = sanitize_text_field( $new_instance['title'] );
		$instance['number'] = (int) $new_instance['number'];		
		return $instance;
	}

}  
 
// Register and load the widget
function tow_recentpost_load() {
    register_widget( 'tow_recentpost_widget' );
}
add_action( 'widgets_init', 'tow_recentpost_load' );