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.
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:
- Sử dụng Genesis 1.8 với language được việt hóa
- Tạo Breadcumbs cho wordpress không cần dùng plugin
- 2 cách để thêm ảnh minh họa vào WordPress Rss Feed
- Fix error OpenID doesnt appear in wordpress comment form
- Bảo Mật Cho WordPress
- 21 thủ thuật SEO cho Blog WordPress (Phần II)
- 21 thủ thuật SEO cho blog WordPress (Phần I)
- Ebook sổ tay WordPress | Thủ thuật blog tiếng Việt toàn tập
- Multi-domain for wordpress site
- Tổng hợp plugin tốt nhất cho WordPress (part 1)
