I've tried to figure out how to display an image in different posts. When I create a post in WordPress it displays a featured image on each post. I have a custom DB with 1000 images and I want to display each image from my DB on each post. I would have 1000 posts, but each with its respective image from the DB, but I can't find where those php files are.
I've already done this in local host. I got a .php file which displays all these images, but I don't know if its just an issue of .php file or I have to code the functions in WordPress.
How about adding customization to your theme's functions.php file in WordPress that reroutes WordPress's default behavior for determining each featured image?
Note: Ideally these types of mods should be added to a child theme rather than the main theme so that updates to your theme do not overwrite your customization.
Here is an example of how this might work:
Added to /wp-content/themes/your-child-theme/functions.php
add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
function my_post_image_html($html, $post_id, $post_image_id) {
// run a query to find the location of your preferred
// image in the alt location. $img is just an example.
$img = "/other_images/otherThumbnail-".$post_id.".jpg";
return '<img src="'.$img.'" alt="modified">';
}
Related
I’ve set up a custom post type and I want the featured image to be cropped an resized for these types of post.
This code in functions.php correctly sizes and crops the featured images:
add_theme_support('post-thumbnails');
add_image_size( 'team_thumb', 719, 719, true);
And something like this makes it appear in the post:
<?php the_post_thumbnail('team_thumb'); ?>
But, the featured image that gets pulled from the page on the Essential Grid, or when sharing on social is still the full sized image.
What do I need to put in my custom post template (or elsewhere in the theme) to make the featured image associated with these custom posts the cropped/resized version?
Wordpress creates thumbnails when the file is uploaded. If you already uploaded images before adding "add_image_size" you must regenerate the thumbnail.
To do so you must use a plugin like "Force regenerate thumbnail" : https://fr.wordpress.org/plugins/force-regenerate-thumbnails/
I am using wordpress and woocommerce. I have one problem, i have created a system with downloads steam market items (names and pictures) and then creates products. But I have one problem, downloaded images that are used for product are automaticly resized to a different resolutions : 150x113 300x225 300x300 425x280 and original one. So it takes 5x space, which is a problem for me. How do i disable or fix that resizing problem.
Thanks.
I found this article here by WP Mayor. Basically you remove the code that produces them.
function wpmayor_filter_image_sizes( $sizes) {
unset( $sizes['medium']);
unset( $sizes['large']);
unset( $sizes['wysija-newsletters-max']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'wpmayor_filter_image_sizes');
function wpmayor_custom_image_sizes($sizes) {
$myimgsizes = array(
"image-in-post" => __( "Image in Post" ),
"full" => __( "Original size" )
);
return $myimgsizes;
}
add_filter('image_size_names_choose', 'wpmayor_custom_image_sizes');
place this in your functions.php file
UPDATE:
Also look here - Seems you just go to the media page, and set the other sizes to 0
By default, WordPress generates three sizes of each image that you upload. Themes and plugins can generate additional images sizes aswell.
First thing you should keep in mind is that the default image sizes are not harmful for your website.
If you already know this but you want to proceed anyway (or your space is really limited), you will need to do some steps to make Wordpress just keep the original image:
First you need to understand how many copies of an uploaded image
are generated by WordPress. You can check that using FTP client and
accesing /wp-content/uploads/ directory.
You can stop WordPress from generating default image sizes by
visiting Settings » Media in WordPress admin area. There you will
see default image sizes predefined by WordPress. You need to set
these sizes to 0 which will prevent WordPress from generating
default image sizes when you upload a new image.
Finally your theme might be generating other thumbnails (check it in
step 1), if this is the case look into your theme’s
functions.php file. Simply look for the code line containing:
add_image_size( 'homepage-thumb', 220, 180, true );
and
set_post_thumbnail_size( 150, 150 );
Note: WordPress uses the thumbnail image size for galleries and theme pages so they might break after you prevent their generation.
If you need further information I suggest you to check the original source of this post.
Hope this helps you.
MAKING YOUR IMAGES LIGHTER (JPEG COMPRESSION HOOK).
It don't take "5x space" but between x1.5 and x3 max, because other sizes are lighter, depending of their dimension and number of different sizes.
But you can make your images even much more lighter with this native hook:
add_filter( 'jpeg_quality', create_function( '', 'return 80;' ) );
You can tune the compression value replacing 80 by a number from 0 to 100. This hook doesn't compress your original image, but only all the others. If you want to use it you will need to paste it in the function.php file of your active child theme or theme.
IMAGES SETTINGS IN WOOCOMMERCE:
They are located in left menu Woocommerce > Settings > Products > Display. You can change all values to 0 (similar to Wordpress Media settings).
As the others answers suggested, you can unset somme of them programatically. Is better to keep thumbnails, because they are used to display images in the media library.
I am trying to remove the featured image from the top of each post. I am using the Pure theme from gt3 themes. The featured image shows up at the top and shoves all the other content to the far right.
I have tried installing the remove featured image plugin, while the tickbox shows up clicking it has no effect. I have also tried editing the page.php and single.php pages within the theme as suggested by several other posts. But the lines they call to be removed are not present in my code (or at least I have not located them). The only code I am seeing (inside singel.php) related to the featured image/thumbnail is:
$featured_image =
wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'single-post-thumbnail');
I have tried removing this with no effect. I have also tried adding something like this to the css
.featured_image_standalone {
display:none;
}
Also no effect. I have a few clients that use the Avada plugin and I have managed to disable the 1st featured image with no problem but I am hoping for a free alternative to purchasing this plugin.
Alternatively, I would be satisfied if I can add additional images below the featured image, leaving the copy to the right. Like on this demo page.
Any help is greatly appreciated! I am a beginner but have been editing/managing WP sites for clients for several months now so I've gotten my hands dirty and with a little instruction I am sure I can remedy this issue.
Thanks!
PS. I tried adding links where appropriate but it appears I can only add 2 in the forum so please ask for clarification and I will post.
It's possible that you're viewing the pages that use template other than page.php.
I'd do the changes to the other template files (in the theme root directory). Also the templates that are dedicated for posts instead of pages.
Commenting that line might lead to an error of calling an undefined variable and/or assign an alternative default value if it isn't defined. So I'd initially experiment with a specific hardcoded thumbnail id like this:
$featured_image =
wp_get_attachment_image_src(
get_post_thumbnail_id( 123 ),
'single-post-thumbnail'
);
'123' being the test id that you're using.
In some environments when PHP gets a fatal error, the server continues to serve the last executable version of the files, hence you might be not witnessing the change because of the fatal error.
Edit
Based on the image that lists the files of the theme provided in the comments, I'd copy the following files, one at a time, to the child theme directory and modify the code there:
page.php
page-contacts.php
single.php
single-team.php
single-gallery.php
image.php
category.php
bloglisting.php
attachment.php
The previous list is ordered by likeliness of the file to be the one you'd want to update, so I'd try one at a time and see the results. Also you'll need to copy these files to the child theme because any modifications to the original files under the parent theme can be erased upon theme upgrade.
To find post ID you can check wp_posts table in phpMyAdmin, if that's not accessible, before anything you can do echo 'post_ID: ' . get_the_ID(); in one of the template files and visit a particular page to see the echo'd ID. Also I think there are some plugins that display the post ID's at the post table withing the admin dashboard UI.
In order to see whether the server serve the last executable files upon fatal error, you can make an echo statement and with every code change to see if the echo get printed.
How do you insert an image from the server folder to the wordpress post with a shortcode, (i don't wanna insert image manually) ?
I've search from google, and see the plugin that approached my desire:
wordpress.org/plugins/folder-gallery/
an example of using this plugin's shortcode is:
[foldergallery folder = "wp-content/uploads/cars"]
(the plugin search for folder cars, and show the image content)
it's good, the plugin will show gallery with lots of thumbnails,
example result:
but this is not what i want.
I want the result is all image in a folder will show up with full size in the post.
is somebody here know another plugin or another way to make it happen, or maybe to create own shortcode to show full image size?
thanks,
Gerga
Just add the HTML anywhere in the post (preferably in he HTML mode of the Editor)
<img src="/wp-content/folder/car.jpg" style="width: 100%,">
You can enable featured images for posts and set their size by using the following code in your function.php file:
add_theme_support('post-thumbnails');
set_post_thumbnail_size(107, 69, true);
but this sets the image size globally for any post types. Im using wordpress 3.0 and have created my own custom post type. Is it possible to apply a different featured thumbnail sizes for different post types?
Thanks
Scott
In your theme functions file, you can define new image sizes that apply to any images uploaded from then forward:
add_image_size('new-thumbnail-size',600,340, true)
Once you've defined a new image size, you can use the_post_thumbnail as usual but include the new image size to display that instead of the thumbnail default:
the_post_thumbnail( 'new-thumbnail-size' )
A little bit more detail: http://gavinsmith.me/2010/10/multiple-post-thumbnail-featured-image-sizes-in-wordpress/
To answer your question, currently (Version 3.4.1) it is not possible. And the reason is simple: If you upload a file to your media library your image is not related to any post nor even a post_type, so wordpress cannot know, that this file has to be resized into a different format.
Realizing your wish (as it is one of mine too) means, that the image has to be created, if an image is added to a post with a custom post type.
So until this might be realized (I do not expect that this will come in time) you have to define your custom image size globally dealing the disadvantage, that every file you are uploading will be stored multiple times (one per add_image_size() call), even if you will use only one image in your template.