mehdi.tayebi 171 ارسال شده در اردیبهشت 98 گزارش بازنشر ارسال شده در اردیبهشت 98 (ویرایش شده) سلام دوستان . بنده برای بخش آخرین نظرات یک ابزارک اختصاصی اومدم ایجاد کردم که کدهاش به صورت زیر هست : <?php /** * WP Comments Widget * * @package WordPress * @subpackage * @since ... 1.0 */ class ZHK_Widget_Comments extends WP_Widget { function __construct() { parent::__construct( 'zhk-widget-comments', 'zhk - آخرین نظرات', array( 'description' => 'ابزارک آخرین نظرات', 'classname' => 'widget-comments', ) ); } public function widget( $args, $instance ) { extract($args); $title = ($instance['title']) ? $instance['title'] : __('آخرین نظرات' , 'acaweb'); $limit = ($instance['limit']) ? $instance['limit'] : 4; echo $before_widget; echo $before_title; echo $title; echo $after_title; ?> <ul id="list-comments"> <?php $args = array( 'status' => 'approve', 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'count' => false, 'number'=> $limit ); $comments = get_comments($args); foreach($comments as $comment) { ?> <li class="item clearfix"> <div class="float-right avatar-comment"> <?php echo get_avatar( $comment->comment_author_email, 45 ); ?> </div> <div class="comment-txt"> <span class="comment-author"> <?php echo $comment->comment_author; ?> <small> : </small></span> <a class="comment-c" href="<?php echo get_permalink($comment->comment_post_ID); ?>"> <?php echo trim(mb_substr(strip_tags($comment->comment_content), 0, 55)) ?> </a> </div> </li> <?php } ?> </ul> <?php echo $after_widget; } public function form( $instance ) { if(!isset($instance['title'])) $instance['title'] = __('آخرین نظرات' , 'acaweb'); if(!isset($instance['limit'])) $instance['limit'] = 4; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('عنوان ','acaweb') ?></label> <input style="width:100%;" type="text" value="<?php echo esc_attr($instance['title']); ?>" name="<?php echo $this->get_field_name('title'); ?>" id="<?php $this->get_field_id('title'); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('تعداد نمایش نظرات : ','acaweb') ?></label> <input type="text" value="<?php echo esc_attr($instance['limit']); ?>" name="<?php echo $this->get_field_name('limit'); ?>" id="<?php $this->get_field_id('limit'); ?>" size="4" /> </p> <?php } } function reg_recent_comments() { register_widget('ZHK_Widget_Comments'); } add_action('widgets_init' , 'reg_recent_comments'); ?> وقتی این ابزارک رو درون قالب خودم به نمایش میزارم با پیغام خطای زیر روبرو می شم : Notice: Undefined index: limit in E:\xampp\htdocs\...\wp-content\themes\...\widgets\class-widget-comments.php on line 27 به این خط من ایراد میگیره : $limit = ($instance['limit']) ? $instance['limit'] : 4; میخواستم ببینم دوستان راه چاره ای برای این موضوع دارند یا خیر ؟ ویرایش شده اردیبهشت 98 توسط mehdi.tayebi نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .