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/cat-title.php
<?php

class post_title extends WP_Widget {
public function __construct(){
$widget_ops = array(
'classname' => 'post_title',
'description' => 'آخرین نوشته ها با دسته بندی',
);
parent::__construct( 'post_title', 'ofogh - تیتر نوشته ', $widget_ops );
}

function widget( $args, $instance ) {
$widget_title = apply_filters( 'widget_title', $instance['widget_title'] );
$post_num = apply_filters( 'post_num', $instance['post_num'] );
$post_cat = apply_filters( 'post_cat', $instance['post_cat'] );
$limit_title = apply_filters( 'limit_title', $instance['limit_title'] );
echo $args['before_widget'];
if( !empty($widget_title) ) {
echo $args['before_title'];
echo $widget_title;
echo $args['after_title'];
}
?>
<ul class="widget_title">
<?php
$catquery = new WP_Query('cat=' . $post_cat . '&posts_per_page=' . $post_num .'');
if( $catquery->have_posts() ) :
while( $catquery->have_posts() ) : $catquery->the_post();
?>
<li><a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>"><?php if($limit_title == "on") : qaleb_title('', '...', true, '70'); else : the_title(); endif; ?></a></li>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
<?php
echo $args['after_widget'];
}

function update( $new_instance, $old_instance ) {
$instance = array();
$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : '';
$instance['post_num'] = ( ! empty( $new_instance['post_num'] ) ) ? strip_tags( $new_instance['post_num'] ) : '';
$instance['post_cat'] = ( ! empty( $new_instance['post_cat'] ) ) ? strip_tags( $new_instance['post_cat'] ) : '';
$instance['limit_title'] = ( ! empty( $new_instance['limit_title'] ) ) ? $new_instance['limit_title'] : '';
return $instance;
}

function form( $instance ) {
if ( isset( $instance[ 'widget_title' ] ) ) {
$widget_title = $instance[ 'widget_title' ];
} else {
$widget_title = 'جدیدترین مطالب';
}

if ( isset( $instance[ 'post_num' ] ) ) {
$post_num = $instance[ 'post_num' ];
} else {
$post_num = '5';
}
if ( isset( $instance[ 'limit_title' ] ) ) {
$limit_title = $instance[ 'limit_title' ];
} else {
$limit_title = 'limit_title';
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'widget_title' ); ?>">نام:</label>
<input name="<?php echo $this->get_field_name( 'widget_title' ); ?>" type="text" value="<?php echo esc_attr( $widget_title ); ?>" id="<?php echo $this->get_field_id( 'widget_title' ); ?>" class="widefat">
</p>
<p>
<label for="<?php echo $this->get_field_id( 'post_cat' ); ?>">دسته بندی</label>
   <select name="<?php echo $this->get_field_name( 'post_cat' ); ?>" id="<?php echo $this->get_field_id( 'post_cat' ); ?>" class="widefat">
   <option value='0'>انتخاب دسته بندی</option>
   <?php foreach(get_categories( array('hide_empty' => 0) ) as $cat) { ?>
   <option value="<?php echo $cat->cat_ID; ?>"><?php echo $cat->cat_name; ?></option>
   <?php } ?>
   </select>
</p>
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id( 'post_num' ); ?>">تعداد نوشته</label>
<input style="width:100%;" name="<?php echo $this->get_field_name( 'post_num' ); ?>" type="number" step="1" min="1" value="<?php echo esc_attr( $post_num ); ?>" size="3" id="<?php echo $this->get_field_id( 'post_num' ); ?>" class="tiny-text">
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'limit_title' ); ?>" id="<?php echo $this->get_field_id( 'limit_title' ); ?>" class="checkbox" <?php checked( $limit_title, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'limit_title' ); ?>">محدود سازی عنوان جهت نمایش بهتر</label>
</p>
<?php
}
}

function post_title_widget() {
register_widget( 'post_title' );
}

add_action( 'widgets_init', 'post_title_widget' );
?>