namayeshesade 2 ارسال شده در مهر 26، 1397 گزارش اشتراک گذاری ارسال شده در مهر 26، 1397 سلام دوستان یه مشکلی دارم اگر میتونید رفعش کنید ممنونم داخل ابزارک های ودرپرس میشه آخرین نوشته هارو اضافه کرد ولی اون نوشته ها تصویر ندارن. فقط متنه میخوام مثل همین نوشته های اخری که داخل خود وردپرس هست ما هم یک ابزارک درست کنیم ولی تصویر کوچیک و تاریخ هم داشته باشه / چطور میشه بدون افزونه این کارو کرد ممنون میشم راهنمایی کنید.افزونه های زیادی هستن ولی من بدون افزونه میخوام انجامش بدم یک قالبی رو هم دارم که کدش رو داره ولی من نتونستم اون رو اضافه کنم کدش رو اینجا قرار میدم ببینید میتونید کاریش کنید ممنونم این فایل داخل قالبه و داخل ابزارک هاش نمایش داده میشه و میتونید اخرین مطالب رو همراه با عکس به نمایش بگذاریم ولی من گذاشتم توی قالبم نیومدش / کد داخل فایل : /////////////////////////////////////////////////////////////////////////////// <?php if ( ! defined( 'ABSPATH' ) ) : exit; // Exit if accessed directly endif; //--------------------------------------------------------------------------- // Latest Post widget //--------------------------------------------------------------------------- class TT_Latest_Post_Widget extends WP_Widget { public function __construct() { parent::__construct( 'materialize_latest_post', // Base ID __('ابزارک آخرین نوشته ها همراه تصویر', 'tokopress'), // Name array('description' => esc_html__('نمایش آخرین نوشته های بلاگ', 'tokopress')) // Args ); } public function form($instance) { $defaults = array( 'title' => '', 'title_length' => '7', 'post_limit' => '5', 'show_meta' => 'yes', 'thumb' => 'yes' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('عنوان: ', 'tokopress'); ?></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($instance['title']); ?>"> </p> <p> <label for="<?php echo $this->get_field_id('title_length'); ?>"><?php esc_html_e('محدودیت عنوان (کلمه): ', 'tokopress'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title_length'); ?>" name="<?php echo $this->get_field_name('title_length'); ?>" type="text" value="<?php echo esc_attr($instance['title_length']); ?>"> </p> <p> <label for="<?php echo $this->get_field_id('post_limit'); ?>"><?php esc_html_e('تعداد نوشته ها برای نمایش: ', 'tokopress'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('post_limit'); ?>" name="<?php echo $this->get_field_name('post_limit'); ?>" type="text" value="<?php echo esc_attr($instance['post_limit']); ?>"> </p> <p> <label for="<?php echo $this->get_field_id('show_meta'); ?>"><?php esc_html_e('نمایش تاریخ نوشته؟ ', 'tokopress'); ?></label> <select class="widefat" id="<?php echo $this->get_field_id('show_meta'); ?>" name="<?php echo $this->get_field_name('show_meta'); ?>" style="width:100%;"> <option value="yes" <?php selected($instance['show_meta'], 'yes'); ?>><?php esc_html_e('بله', 'tokopress') ?></option> <option value="no" <?php selected($instance['show_meta'], 'no'); ?>><?php esc_html_e('خیر', 'tokopress') ?></option> </select> </p> <p> <label for="<?php echo $this->get_field_id('thumb'); ?>"><?php esc_html_e('نمایش تصویر شاخص نوشته؟ ', 'tokopress'); ?></label> <select class="widefat" id="<?php echo $this->get_field_id('thumb'); ?>" name="<?php echo $this->get_field_name('thumb'); ?>" style="width:100%;"> <option value="yes" <?php selected($instance['thumb'], 'yes'); ?>><?php esc_html_e('بله', 'tokopress') ?></option> <option value="no" <?php selected($instance['thumb'], 'no'); ?>><?php esc_html_e('خیر', 'tokopress') ?></option> </select> </p> <?php } public function update($new_instance, $old_instance) { $instance = $old_instance; $instance[ 'title' ] = (!empty($new_instance[ 'title' ])) ? strip_tags($new_instance[ 'title' ]) : ''; $instance[ 'title_length' ] = (!empty($new_instance[ 'title_length' ])) ? strip_tags($new_instance[ 'title_length' ]) : '7'; $instance[ 'post_limit' ] = (!empty($new_instance[ 'post_limit' ])) ? strip_tags($new_instance[ 'post_limit' ]) : '5'; $instance[ 'show_meta' ] = (!empty($new_instance[ 'show_meta' ])) ? strip_tags($new_instance[ 'show_meta' ]) : 'yes'; $instance[ 'thumb' ] = (!empty($new_instance[ 'thumb' ])) ? strip_tags($new_instance[ 'thumb' ]) : 'yes'; return $instance; } public function widget($args, $instance) { echo $args[ 'before_widget' ]; $title = apply_filters('widget_title', $instance[ 'title' ]); if (!empty($title)) { echo $args[ 'before_title' ] . $title . $args[ 'after_title' ]; } ?> <ul class="posts"> <?php $pargs = array( 'post_type' => 'post', 'posts_per_page' => $instance[ 'post_limit' ], 'post_status' => 'publish', 'post__not_in' => get_option('sticky_posts') ); $the_query = new WP_Query($pargs); if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> <li> <?php $thumb_id = get_post_thumbnail_id(); // Get the featured image id. $image = wp_get_attachment_image_src($thumb_id, 'blog-thumbnail-widget'); // Get img URL. // if ($instance[ 'thumb' ] == 'yes') : if (has_post_thumbnail()) : ?> <a class="media-left" href="https://go.20script.ir/index.php?url=<?php the_permalink(); ?>"> <img src="<?php echo esc_url($image[ 0 ]); ?>" alt="<?php echo esc_attr(get_the_title()); ?>"> </a> <?php endif; endif; ?> <?php $instance[ 'title_length' ] = isset($instance[ 'title_length' ]) ? $instance[ 'title_length' ] : ''; ?> <a href="https://go.20script.ir/index.php?url=<?php the_permalink(); ?>" class="title"><?php echo wp_trim_words(get_the_title(), $instance['title_length']); ?></a> <?php if ($instance[ 'show_meta' ] == 'yes') : ?> <span class="date"><i class="fa fa-clock-o" aria-hidden="true"></i><?php the_time('j M Y') ?></span> <?php endif; ?> </li> <!-- /.media --> <?php endwhile; wp_reset_postdata(); ?> <?php else : ?> <p><?php esc_html_e( 'Post Not Found!', 'tokopress'); ?></p> <?php endif; ?> </ul> <!-- latest-post --> <?php echo $args[ 'after_widget' ]; } } // register widgets if (!function_exists('tt_latest_post_widget_register')) { function tt_latest_post_widget_register() { register_widget('TT_Latest_Post_Widget'); } add_action('widgets_init', 'tt_latest_post_widget_register'); } لینک به دیدگاه به اشتراک گذاری در سایت های دیگر More sharing options...
laruz 983 ارسال شده در مهر 27، 1397 گزارش اشتراک گذاری ارسال شده در مهر 27، 1397 افزونه php code widget رو نصب کنین که بتونین دستورات php رو هم بنویسین. لینک به دیدگاه به اشتراک گذاری در سایت های دیگر More sharing options...
Masih 6,279 ارسال شده در مهر 27، 1397 گزارش اشتراک گذاری ارسال شده در مهر 27، 1397 درود. بجای عدد 3 تعداد مطالبی که می خواهید نمایش داده بشه رو وارد کنید : <?php $args = array( 'posts_per_page' => '3' ); $recent_posts = new WP_Query($args); while( $recent_posts->have_posts() ) : $recent_posts->the_post() ?> <li> <a href="https://go.20script.ir/index.php?url=<?php echo get_permalink() ?>"><?php the_title() ?></a> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </li> <?php endwhile; ?> <?php wp_reset_postdata(); # reset post data so that other queries/loops work ?> کد رو هم در فایلی از قالب که می خواهید آخرین مطالب نمایش داده بشه قرار بدید. لینک به دیدگاه به اشتراک گذاری در سایت های دیگر More sharing options...
namayeshesade 2 ارسال شده در مهر 27، 1397 مالک گزارش اشتراک گذاری ارسال شده در مهر 27، 1397 در 32 دقیقه قبل، Masih گفته است : درود. بجای عدد 3 تعداد مطالبی که می خواهید نمایش داده بشه رو وارد کنید : <?php $args = array( 'posts_per_page' => '3' ); $recent_posts = new WP_Query($args); while( $recent_posts->have_posts() ) : $recent_posts->the_post() ?> <li> <a href="https://go.20script.ir/index.php?url=<?php echo get_permalink() ?>"><?php the_title() ?></a> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </li> <?php endwhile; ?> <?php wp_reset_postdata(); # reset post data so that other queries/loops work ?> کد رو هم در فایلی از قالب که می خواهید آخرین مطالب نمایش داده بشه قرار بدید. ممنون که وقت گذاشتید مدیر جان اگر بخوام به صورت ابزارک در بیارمش باید چیکار کنم لینک به دیدگاه به اشتراک گذاری در سایت های دیگر More sharing options...
Masih 6,279 ارسال شده در مهر 27، 1397 گزارش اشتراک گذاری ارسال شده در مهر 27، 1397 برای تبدیل به ابزارک، این کد رو انتهای فایل functions.php قالب قرار بدید : function moovier_movie_year_widg() { register_widget( 'myear_wdgt' ); } add_action( 'widgets_init', 'moovier_movie_year_widg' ); // Creating the widget class myear_wdgt extends WP_Widget { function __construct() { parent::__construct( // Base ID of your widget 'myear_wdgt', // Widget name will appear in UI __('آخرین مطالب با تصویر', 'dm-moovier'), // Widget description array( 'description' => __( 'آخرین مطالب با تصویر شاخص', 'dm-moovier' ), ) ); } // Creating widget front-end public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); // before and after widget arguments are defined by themes echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; // This is where you run the code and display the output get_template_part( 'last', 'posts' ); echo $args['after_widget']; } // Widget Backend public function form( $instance ) { if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( 'آخرین مطالب با تصویر', 'dm-moovier' ); } // Widget admin form ?> <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> <?php } // Updating widget replacing old instances with new public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; return $instance; } } // Class wpb_widget ends here function moov_addicon_movieyear() { ?> <style> *[id*="myear_wdgt"] > div.widget-top > div.widget-title > h3:before { font-family: "dashicons"; content: "\f236"; width:33px; float:right; height:6px; margin-top:-5px; font-size:22px; } </style> <?php } add_action('admin_head-widgets.php','moov_addicon_movieyear'); بعد یک فایل به نام last-posts.php در پوشه قالب ایجاد کنید (دقیقا همونجایی که فایل functions.php و style.css قرار دارن) و کد زیر رو داخلش قرار بدید و شخصی سازی کنید: <?php $args = array( 'posts_per_page' => '3' ); $recent_posts = new WP_Query($args); while( $recent_posts->have_posts() ) : $recent_posts->the_post() ?> <li> <a href="https://go.20script.ir/index.php?url=<?php echo get_permalink() ?>"><?php the_title() ?></a> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </li> <?php endwhile; ?> <?php wp_reset_postdata(); ?> لینک به دیدگاه به اشتراک گذاری در سایت های دیگر More sharing options...
پست های پیشنهاد شده
بایگانی شده
این موضوع بایگانی و قفل شده و دیگر امکان ارسال پاسخ نیست.