HEX
Server: Apache/2
System: Linux localhost 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64
User: rasad (1007)
PHP: 7.4.33
Disabled: shell_exec,system,passthru,exec,popen,ini_restore,socket_create,socket_create_listen,socket_create_pair,socket_listen,socket_bind,symlink,link,pfsockopen,ini_alter,dl,pcntl_exec,pcntl_fork,proc_close,proc_open,proc_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_uname,show_source,getfile,mkfifo
Upload Files
File: /home/rasad/domains/rasadeardakan.ir/private_html/wp-content/themes/ofogh/widget/all.php
<?php
class qaleb_all_widget extends WP_Widget {
public function __construct(){
$widget_ops = array(
'classname' => 'qaleb_all_widget',
'description' => 'آخرین مطالب، عکس، فیلم',
);
parent::__construct( 'qaleb_all_widget', 'ofogh - همه نوشته ها ', $widget_ops );
}	
	function widget( $args, $instance ) {
		extract($args, EXTR_SKIP);
		echo $before_widget;
		echo $before_title;
		//Display title as stored in this instance of the widget
		echo esc_html($instance['news_title']); 
		echo $after_title;
		print_qaleb_all_widget($instance);
		echo $after_widget;
	}
	
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance['news_title'] = $new_instance['news_title'];
		$instance['select_news'] = $new_instance['select_news'];
		$instance['news_cat'] = $new_instance['news_cat'];
		$instance['news_count'] = $new_instance['news_count'];
		return $instance;
	}

	function form( $instance ) {
		$defaults = array(
			'news_title' => 'جديدترين ها',
			'news_count' => '8',
		);
		$instance = wp_parse_args( (array) $instance, $defaults );
		?>	
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id('news_title'); ?>">عنوان</label>
<input style="width:100%;" type="text" id="<?php echo $this->get_field_id( 'news_title' ); ?>" name="<?php echo $this->get_field_name( 'news_title' ); ?>" value="<?php echo $instance['news_title']; ?>" />
</p>
<p>					
<label style="width:100%;" for="<?php echo $this->get_field_id('select_news'); ?>">نوع نمايش </label>
<select style="width:100%;" class="select-type" id="<?php echo $this->get_field_id('select_news'); ?>" name="<?php echo $this->get_field_name('select_news'); ?>" type="text">
	<option value="1">آخرین</option>
	<option value="2">تصادفی</option>
</select>
</p>
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id('news_count'); ?>">تعداد نوشته</label>
<input style="width:100%;" type="number" step="1" min="1" id="<?php echo $this->get_field_id( 'news_count' ); ?>" name="<?php echo $this->get_field_name( 'news_count' ); ?>" value="<?php echo $instance['news_count']; ?>" />
</p>
		<?php
		
		echo '<script>';
		echo 'document.getElementById("'. $this->get_field_id( 'select_news' ) .'").value = "' . $instance['select_news'] . '";';
		echo 'document.getElementById("'. $this->get_field_id( 'news_title' ) .'").value = "' . $instance['news_title'] . '";';
		echo 'document.getElementById("'. $this->get_field_id( 'news_count' ) .'").value = "' . $instance['news_count'] . '";';
		echo '
			jQuery(function($) {
				$("#'. $this->get_field_id('select_news'). '").change(function(){
					if($("#'. $this->get_field_id('select_news'). '").val() == "3") {
						$(".select-cat").show(); 
					} else {
						$(".select-cat").hide(); 
					} 
				});
			});
		</script>';
	}
	
}
function qaleb_all_widget_register() {
	register_widget( 'qaleb_all_widget' );
}
add_action( 'widgets_init', 'qaleb_all_widget_register' );

function print_qaleb_all_widget($options) { ?>
<div class="all-post">
<ul>
				<?php
					if($options['select_news']==1){
						$big_query = new WP_Query(array(
						'post_status' =>'publish',
						'post_type' => array('post','video','gallery'),
						'posts_per_page' => $options['news_count']));
						
					} elseif ($options['select_news']==2) {
						
						$big_query = new WP_Query(array(
						'post_status' =>'publish',
						'post_type' => array('post','video','gallery'),
						'orderby' => 'rand',
						'posts_per_page' => $options['news_count']));
						
					}
					if($big_query->have_posts()) : while($big_query->have_posts()) : $big_query->the_post();
					?>
<li class="<?php if(get_post_type() == "video"){ ?>media-all <?php }else if(get_post_type() == "gallery"){ ?> gallery-all <?php } ?>"> <?php if(get_post_type() == "video"){ ?> <i class="fa fa-play"></i> <?php }else if(get_post_type() == "gallery"){ ?> <i class="fa fa-camera"></i><?php } ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; wp_reset_query(); ?>
</ul>
</div>
<?php
}
?>