I've edited a Bootstrap Wordpress theme to display featured images randomly when refreshed on the front page. But now on every other line the images are displaying huge gaps instead of images -
Here is my site.
What have I done wrong, and how do I get rid of these gaps? I used this code in index.php to display the images randomly -
<?php /* Start the Loop */ ?>
*<?php query_posts($query_string . '&orderby=rand') ?>*
<?php while ( have_posts() ) : the_post(); ?>
The source of the problem is that the images aren't all the same height. In the row right at the top of the screen grab you've pasted, the image on the right isn't as tall as the other two. So the browser thinks there's space for content underneath it. It adds an image there, and tries to float it left. It stops when it bumps up against something - the image in the second column in the row above. Then it stops. And the next image gets put underneath it. It's just the way float works in CSS.
So you have two options. Either crop all your images (or their containers, say the articles) to the same height, or use a jQuery library like masonry to lay out your images.
See this answer for a related problem and more discussion.
Don't float in the .pbox css. Use display: inline-block instead and you're good.
See screenshot and updated css at bottom-right: https://www.dropbox.com/s/3qvmhvz5dwlnekb/Screenshot%202014-04-16%2022.14.42.png
In short the gaps come from floating images left that aren't equal heights. You have two options to fix this with out editing your current HTML markup.
Option 1
Add a new image size, add that image size to the wp_query and regenerate your thumbnails.
3 Steps:
1) Create a new image size by adding the following to functions.php
add_image_size( 'home-thumbnail', 400, 400, true);
home-thumbnail = size variable, keep it simple and short
400, 400 = height, width
true = hard crop, WP will crop the image from the center.
http://codex.wordpress.org/Function_Reference/add_image_size
2) Add the new image size to the wp query.
e.g. <?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'home-thumbnail' );
}
?>
3) Regenerate your thumbnails with this plugin: http://wordpress.org/plugins/regenerate-thumbnails/
That's it!
Options 2
Pre-crop your images before upload so they're the same size. I'd recommend Opt 1 as these steps are apart of any development workflow and will ultimately increate your development flexibility / options.
Related
I have issues to make thunmbnails size on different devices display.
on Mobile size display, it still shows large thunmbnials size, it does not auto adjust image size to fit mobile devices. please advise.
Please check the attached img. thanks
I would suggest creating speicifc image sizes for your uploaded image and then you srcset's to trigger which image is shown at what size.
For the image sizes, use the following in your functions.php:
add_image_size('mobile', 480, '', false);
This would create the 'mobile' size at 480px in width and the correct ratio'd height depending on the image.
Once you've created this, you will be able to call this version of the image. If you need any further help, let me know.
Add mobile detect plugin and add below condition so it will work for you.
https://wordpress.org/plugins/mobble/
You can use diffrent different size based on condition.
<?php
if (is_mobile()) {
the_post_thumbnail('medium');
} else {
the_post_thumbnail('large');
} ?>
The image I uploaded on wordpress had a dimension of 250x357 and gets uploaded good at this page. But the same image is being cropped to 250x240 on this page. I don't know what to do, and I tried alot of things but the image just gets cropped.
Also the image on the homepage (second link) must be 300x250, just want the image to be resized to fit it without streching. So with white borders.
You must find articles loot. And find call to featured image function. Maybe it's use wp_get_attachment_image(). Than you need change wp_get_attachment_image( $image ,'cb-360-240'); to wp_get_attachment_image( $image ,'full');.
I met a problem when trying to change the media setting. The first pic wass about Media Setting and how big a large/medium/thumbnail image is. I tried to make large for 960px.
The second picture was what I saw when trying to resize image in editing page. But I couldn't see the 960px option.
I'd tried some sizes smaller than 640px in Media Setting. It worked. And if for some larger than 640px, like 641px and 960px, it showed only 640px. It seemed not to be able to reach 960px that large.
So, why can't I use 960px?
I used a blank theme to make styles from the ground. And so far, I've not changed any function for image setting at all.
Most themes (esp. themes from wordpress) have a specific width limit (measured in pixels) for images inserted in a post or a page. Obviously, that limit depends on the theme’s main column width (which varies greatly from theme to theme).
/wp-includes/media.php has:
// we're inserting a full size image into the editor. if it's a really big image we'll scale it down to fit reasonably
// within the editor itself, and within the theme's content width if it's known. the user can resize it in the editor
// if they wish.
if ( !empty($GLOBALS['content_width']) ) {
$max_width = $GLOBALS['content_width'];
}
else
<strong>$max_width = 500;</strong>
Try overriding with $GLOBALS['content_width'] = 960; in the theme's function.php
As #Debajyoti Das explains, there is a set content width for most themes.
Either find the width in your theme and amend (search the files for 640) or if you have a child theme then add the following code in your functions.php which will usually override the themes width settings.
For instance this works with the Understrap framework:
// set theme width
global $content_width;
$content_width = 1024;
http://cameleonjackets.com/product-category/fall-2014/
The models heads are being cut off. How can I align the photo to the top? I've tried adjusting the photo sizes and the columns, but I want to keep the layout and product images as is. Is there a way to do this with CSS? Thanks!
The issue isn't with CSS. It's with the fact that your CMS is cropping the images, and doing so from the center of your images.
First you need to disable cropping on your generated thumbnails. Settings in wordpress will be found at
Dashboard > settings > media
and (depending on your installation of woocommerce)
Dashboard > Woocommerce > Settings > Product > Product Image Sizes
You will also need to disable cropping anywhere in your themes code that could be causing problems. Look for functions that look the similar to
add_image_size( $name, $width, $height, $crop );
Where $crop would be a true false statement that we want to be false.
Then you will need to have your thumbnails regenerated.
You can use this plugin to do that.
Then you can use css to set the size of whatever wraps your images as well as set overflow:hidden and then set the image styles min-width and min-height to 100%. That way if you upload different sized images it still appears to be properly cropped.
I want to remove FlexSlider from my WordPress WooTheme (Astrum) since it looks terrible. It makes our images full-size, so our images look silly.
I would prefer to have a thumbnail gallery where you can click on an image and it becomes 400px x 400px or something more standard; can anyone help me with removing flexslider and replacing with a gallery?
http://dv8sports.inpresence.us/product/bag-1/ for example
Flex slider is responsive. That means if you wrap slider inside some container it will stretch.
I would try to wrap the slider inside some other container which defines the preferred width. Your theme supports column shortcodes - use that.
According to their documentation, you can do something like:
[column width="one-third" place="first" ][/column]
[column width="one-third" place="first" ] Slider shortcode here [/column]
[column width="one-third" place="last" ][/column]
Another point: You submitted link to a product page and that page expects to contain product description and other stuff / not just a single image. Once you build the product page properly (add content) your image size will shrink according to surrounding content.
Hopefully this helps.