Lấy ảnh minh họa cho plugin Upprev WordPress khi không đặt Featured Image

Một điểm mà mình vẫn chưa làm được đó là khi post bài thường hay quên việc đặt Featured Image, và chính vì thế nếu theme không hỗ trợ tự động lấy 1 ảnh bài viết ra làm hình đại diện thì cảm giác bị trống sẽ rất khó nhìn :D, hiện tại hầu hết các theme đều có hỗ trợ Featured Image nhưng chúng ta phải chọn ảnh để làm trong khi post bài.

upPrev wordpress plugin option

Bài viết này chỉ hướng dẫn bạn làm điều này với plugin Uprev của WordPress, plugin này cho phép làm nổi bật các bài viết mỗi khi có sự kiện người dùng kéo thanh cuộn xuống đến cuối trang thì plugin này sẽ slide out ra một bài viết.

Hình ảnh plugin khi chưa add thumbnail:

Hình ảnh plugin khi thêm thumbnail:

Để làm được như trên, bạn hãy mở file upprev.php trong thư mục wp-content/plugins/upprev/

Tìm đến và thay thế nội dung vòng if :


if ( current_theme_supports('post-thumbnails') && $show_thumb && has_post_thumbnail( get_the_ID() ) ) {

...

} else {

Bằng nội dung bên dưới đối với bản UpPrev 3.2:


            if ( current_theme_supports('post-thumbnails') && $show_thumb) {

				$args = array(
				'post_type' => 'attachment',
				'numberposts' => 1,
				'post_status' => null,
				'post_parent' => get_the_ID()
				);

				$attachments = get_posts( $args );

                $item_class .= ' upprev_thumbnail';

                $image = sprintf(

                    '<a class="upprev_thumbnail" title="%s" href="%s" rel="%s">%s</a>',

                    $permalink,

                    wptexturize(get_the_title()),

                    $ga_click_track,

                    $current_post_title,

                    apply_filters(

                        'iworks_upprev_get_the_post_thumbnail', wp_get_attachment_image(

                            $attachments[0]->ID,

                            array(

                                $iworks_upprev_options->get_option( 'thumb_width' ),

                                9999

                            ),0,

                            array(

                                'title'=>get_the_title(),

                                'class'=>'iworks_upprev_thumb'

                            )

                        )

                    )

                );

            } else {

Bằng nội dung bên dưới đối với bản UpPrev 3.3:

            if ( current_theme_supports('post-thumbnails') && $show_thumb) {

                $item_class .= ' upprev_thumbnail';
			$args = array(
			'post_type' => 'attachment',
			'numberposts' => 1,
			'post_status' => null,
			'post_parent' => get_the_ID()
			);

			$attachments = get_posts( $args );

                $image = sprintf(

                    '<a href="%s" title="%s" class="upprev_thumbnail"%s rel="%s">%s</a>',

                    $permalink,

                    wptexturize(get_the_title()),

                    $ga_click_track,

                    $current_post_title,

                    apply_filters(

                        'iworks_upprev_get_the_post_thumbnail', wp_get_attachment_image(

                            $attachments[0]->ID,

                            array(

                                $iworks_upprev_options->get_option( 'thumb_width' ),

                                9999

                            ),

                            array(

                                'title'=>get_the_title(),

                                'class'=>'iworks_upprev_thumb'

                            )

                        )

                    )

                );

            } else {

Tham khảo:

Hãy để lại ý kiến

Kèm theo bài viết gần đây nhất từ web của bạn
Read previous post:
Đăng ký tên miền tại Yahoo chỉ với $1.99/năm

Yahoo đang trong chương trình khuyến mãi đăng ký tên miền com net info org với chỉ $1.99/năm và chỉ...

Close