The function km_rpbt_related_posts_by_taxonomy still gets the related posts objects. To only get posts that have a post thumbnail you can use this for the arguments:
$args = array(
'posts_per_page' => 10,
'post_thumbnail' => true,
);
The widget and shortcode use this function to display the post thumbnails:
http://keesiemeijer.wordpress.com/related-posts-by-taxonomy/functions/#km_rpbt_related_posts_by_taxonomy_gallery
But if you want, you can use any of the post thumbnail functions in your own template:
http://codex.wordpress.org/Post_Thumbnails#Function_Reference
Thanks for quick response.
I tried using this code
<?php
// first get the related post objects with the km_rpbt_related_posts_by_taxonomy() function.
// check if the function already exists
if ( function_exists( 'km_rpbt_related_posts_by_taxonomy' ) ) {
$args = array(
'posts_per_page' => 8,
'post_thumbnail' => true, // only gets the posts that have a post thumbnail
);
$taxonomies = array( 'category' );
$post_id = $post->ID; // post id available inside the loop.
$related_posts = km_rpbt_related_posts_by_taxonomy( $post_id , $taxonomies, $args );
// check if related post were found
if ( $related_posts ) {
$defaults = array(
'columns' => 2,
'size' => 'medium',
);
// display the related post thumbnail gallery
echo km_rpbt_related_posts_by_taxonomy_gallery( $args, $related_posts );
}
}
?>
It displays the post with thumbnails, but, the ‘columns’ settings doesn’t works for me, I tried, to make them display only in 1 code by no results. Also the thumbnail is not resizing on defining ‘small’ or ‘large.’
Please help me with this! (BTW I don’t know PHP)
Arrg, I just noticed an error in the documentation.
Change this:
$defaults = array(
'columns' => 2,
'size' => 'medium',
);
to this:
$args = array(
'columns' => 2,
'size' => 'medium',
);
[updated documentation]
Thank you so much, but one more issue. It seems like the default thumbnail size of the post thumbnails is big (420 x 334) and changing settings to small, medium, and large doesn’t works either.
Please help me how to define those sizes using my functions.php ?
Try setting the size to ‘thumbnail’. Default sizes are “thumbnail”, “medium”, “large”, “full”.
You can set your own thumbnail sizes in your theme’s functions.php with add_image_size():
http://codex.wordpress.org/Function_Reference/add_image_size
Check if your theme’s functions.php adds any new thumbnail sizes you like.
Brilliant, it completely solved my problem. Thanks a lot for your kind support 🙂
Now, the one last thing I just noticed that, indeed the post thumbnail sizes changes, but, actually it just scales the real size of image to the one I had set in the functions file. And despite of the low resolution of the post thumbnail, it size remains same. So, isn’t there a way we can reduce the size as, well?
So, isn’t there a way we can reduce the size as, well?
Can you explain a bit more and/or share a link to your site where we can see the problem.
Well, by those words I mean, that the size(kbs) of the cropped thumbnails should be smaller.
Because a post thumbnail image with 284 x 225 resolution, sizes around 30KB while, the original image compressed using Photoshop with a resolution of 480 x 320 also sizes 32KB. (notice the difference, the post thumbnail size should be lesser, somewhat around 15-20kb)
However, I think it might be because of poor compression method WordPress might be using to crop post thumbnail images.
When you upload new images your new (smaller) size will be used. For older images you can regenerate thumbnail sizes with this plugin:
http://wordpress.org/plugins/regenerate-thumbnails/
Before you use the regenerate thumbnails plugin I think it’s best you create a full backup of your site (images and database): http://codex.wordpress.org/WordPress_Backups
Thank you so much Keesiemeijer, for your amazing support, and wonderful plugin 🙂
You’re welcome. I’m glad you like it and that your issue is resolved 🙂
Hey there, I was wondering on how to make the related posts with thumbnails to show with hyperlinked title?
To remind you again, I am using this code to display related post with thumbnails. It works without a flaw. But, the problem is that the related posts shown with this code, only shows the images linked to their respective URLs, and the post title displayed in a stripped plain texts. I just want these related posts titles to be displayed, hyperlinked, along with the post images. I hope you’re getting my issue, please tell me how to do so?
<?php
// first get the related post objects with the km_rpbt_related_posts_by_taxonomy() function.
// check if the function already exists
if ( function_exists( 'km_rpbt_related_posts_by_taxonomy' ) ) {
$args = array(
'posts_per_page' => 10,
'post_thumbnail' => true, // only gets the posts that have a post thumbnail
);
$taxonomies = array( 'movie' );
$post_id = $post->ID; // post id available inside the loop.
$related_posts = km_rpbt_related_posts_by_taxonomy( $post_id , $taxonomies, $args );
// check if related post were found
if ( $related_posts ) {
$args = array(
'columns' => 2,
'size' => 'thumbnail',
);
// display the related post thumbnail gallery
echo km_rpbt_related_posts_by_taxonomy_gallery( $args, $related_posts );
}
}
?>
Thanks!
Right now this is not possible, but I’m working on version 0.2.1 of the plugin which will also add a new filter to alter the thumbnail (and post title) output. I think it will be ready in the comming weeks.
Thanks, I had just implemented this filter 🙂
Works perfectly!