the_post_thumbnail(array(X,Y)) doesn't work well - wordpress

The size of my posts’ featured images is 700x400 or more, and in order to display them center-cropped to 300x400 I use :
the_post_thumbnail(array(300,400));
However this code displays everything except a 300x400 image. Anybody could tell me how to achieve what I want ?

As the function manual says:-
PLEASE NOTE: The crop does not work in
Wp 3.0+. All that is needed for WP
3.0+ is the call for the thumbnail to post. Then proceed to media in the
dashboard and set your thumbnail to
crop to the size you wish to use.
http://codex.wordpress.org/Function_Reference/the_post_thumbnail

See here: http://gavinsmith.me/2010/10/multiple-post-thumbnail-featured-image-sizes-in-wordpress/
You can dig a bit further than using only the_post_thumbnail and actually create your own image sizes. Then, using the_post_thumbnail, you can call the image - but the version you have created using add_image_size, as described on that page. Let me know if I lost you there.

try out this
<?php echo the_post_thumbnail(array(32,32)); ?>
You can Increase size on desire

Related

Wordpress - remove all classes added by WP on pictures

When I add pictures in an article on wordpress, wordpress automatically add classes to the pictures.
eg :
I simply want to desactivate those added classes, of which I do not see the point and actually annoys me when I want to center a group of pictures.
How can I do so?
I've read about the following filter :
add_filter( 'get_image_tag_class', '__return_empty_string' );
But given that the pictures classes seems dynamical (picture id?), how can I do so? And... where should I do that fork?
Any other method to clean that code?
Thanks !
Solved as previously mentionned in the answers, thanks !

Wordpress select and crop in plugin

I needs to upload images in my plugin and use wp.media for this task.
According to https://codex.wordpress.org/Javascript_Reference/wp.media
Its work, but I needs to have "Select and Crop" option in media library after upload my image with custom size.
I was see this in default theme in appearence custom header image, but can't understand how I can use this in my plugin with wp.media js?
This my not be better solution but work in wordpress :)
i use Thumbnail Crop Position and Simple Image Sizes for that :)
Good luck! :)
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('yourImageSize');
}?>
See my answer posted here that does Select and Crop using the Media Library on a theme options page. You can use it as a starting point for getting it to work in a plugin:
https://wordpress.stackexchange.com/questions/281760/using-media-uploader-to-select-image-of-specific-size-enforce-cropper/302962#302962

Wordpress - How to change thumbnail size on Homepage? Can't find reference

I've searched throughout and can't find where to change the base thumbnail size on the Homepage (www.tomcpalead.com). It's set to 210 x 158. I change the Functions.php and nothing updates on the Homepage. Can't find the reference in style.css to edit it either.
Can someone help?
Thanks
The size of your thumbnails seems to be coming from here:
http://tomcpalead.com/?custom-css=1&csblog=1&cscache=6&csrev=4
I haven't seen CSS files named like that before though, so I'll defer to others who will have a better idea of where that's coming from. If there's any setting somewhere in your theme that looks like the following then that is what I would try editing:
.river .thumb img{width:16rem;height:9.75rem}
Just go to wordpress admin and follow this path :
Go to admin => Settings => Media
here, you will get the thumbnail size for all the images defined. You can change it as per your choice.
After modifying size, just check it by uploading a new image and set it a thumbnail image.

Setting thumbnail featured image size not working properly

Hi I just started today on creating my first Wordpress Theme and I am trying to create a featured Image for each post.Aldo I have managed to acomplish that it seems that the sizes I am giving it are not taking effect.Here is my code:
if(function_exists('add_theme_support')){
add_theme_support('post-thumbnails' , array('post'));
set_post_thumbnail_size(200,120);
}
if(function_exists('has_post_thumbnail') && has_post_thumbnail()){
the_post_thumbnail();
}
It seems that my featured images are not always set to the same size.For example if the image is smaller then what size I set it will remain the same , for big images the width is the same but for some the height is different.
What am I doing wrong here?
Are you setting the thumbnail size in functions.php? It will not work properly if it's just in index.php or another theme file.
From the codex:
This feature must be called before the init hook is fired. That means
it needs to be placed directly into functions.php or within a function
attached to the 'after_setup_theme' hook. For custom post types, you
can also add post thumbnails using the register_post_type function as
well.
the_post_thumbnail() displays the thumbnail and should be placed where you want the thumbnail to display.

How would you recommend adding an image as a custom field in WordPress?

I need to add an image to each page in WordPress.
I don't wish to insert it using the WYSIWYG editor, I just need the url as a custom field, which I later use in the template.
I tried using the CFI plugin (Custom Field Images), and I hacked my way into getting it to work with the rest of my plugins, but then I moved the site to the production server and CFI just didn't work for some reason.
I can't seem to find any other plugin that just lets you pick an image from the library and add it as a custom field.
I've downgraded to the point where I'm willing to manually enter all the URLs into each and every page. but before I do, I thought I'd check here.
Can anyone tell me what's the easiest, best way to add images as custom fields in WordPress (2.7.1 if it matters)?
In our WordPress template, each post generally only has one image 'attached', which is displayed outside the posts' (textual) content.
I simply upload the file using the edit posts' media uploader, never insert it into the post like JoshJordan above, then retrieve the image using a bit of code in the right place in my template file.
This would also work if you're using more than one image in your post, eg. in your post content. As long as you keep the image used as the 'main' post image as the first image (remember you can re-order images in your posts' image library by dragging them up and down), you're easily able to call it anywhere in your template file by using something like this:
<?php
$img_size = 'thumbnail'; // use thumbnail, medium, large, original
$img_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts where post_parent= $post->ID and (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/gif') and post_type = 'attachment'");
$img_array = wp_get_attachment_image_src($img_id,$img_size,false);
echo '<img src="'.$img_array[0].'"' title="'.get_the_title().'" />';
?>
No need for copying and pasting image urls.
The template I have uses a manually-entered custom field for the splash image of each post. When I'm done writing my article, I upload an image, copy its URL from the upload tool, never insert it into my post, and then paste that URL into the "Image" custom field. Simple as pie and takes only seconds. Insignificant compared to the amount of time it takes me to write an article.
You can use the custom key value fields on posts as well. let's say you always give your images the key 'thumb'. you can then use this code to output them in your post as a thumbnail:
<?php
$values = get_post_custom_values("thumb");
echo “<img src=\”$values[0]\” class=\”thumb\”></a>”; ?>
Consider using Flutter it's a bit tricky to figure out at first, and has many really useful featured, including EIP (edit in place), and image handling.
After installing the plugin create a new "Write Panel", you'll figure it out from there. The plugin provides you with a rather intuitive GUI, which includes an image uploader. The template tags are very easy to use, I believe it's something like
<?php echo get_image('name_of_field'); ?>
I just had to build a site for a client that needed the same feature, I ended up using Flutter.

Resources