wordpress 3.5.1 Featured Image not showing up...? - wordpress

This is what inside my function.php
<?php
if ( function_exists( 'add_theme_support' )){
add_theme_support( 'post-thumbnails' );
}
if ( function_exists( 'add_image_size' )){
add_image_size('featured', 400, 340, true);
add_image_size('post-thumb', 100, 140, true);
}
?>
This is what inside my index.php
<?php the_post_thumbnail('post-thumb'); ?>
Featured Image in Screen Options enabled.
Featured Image metabox displaying on Edit Post
Featured Image is set.
the problem is the thumbnail not showing in index.php(homepage). Am I missing something? Big thanks in advance.

Put below code just above: the_content();
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('post-thumb');
}
?>
See it for more information: http://codex.wordpress.org/Function_Reference/the_post_thumbnail and https://wordpress.stackexchange.com/questions/39798/thumbnail-cropping-with-add-image-size

Replace nonworking code
add_theme_support(‘post-thumbnails’);
with working variant:
add_theme_support( ‘post-thumbnails’, array( ‘post’, ‘page’, ‘player’ ) );

Related

Custom WordPress Image size not displaying

I am trying to add a custom image size in WordPress like so:
// Add custom image sizes
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' ); // The important part
}
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'home_portrait size', 1000, 1000, false );
}
/* Display Custom Image Sizes */
add_filter('image_size_names_choose','wpshout_custom_sizes');
function wpshout_custom_sizes($sizes){
return array_merge($sizes, array(
'home_portrait' => __('Home Portrait standard'),
));
}
I can see this extra size is generated when I upload an image to the media library as expected but it does not work when I try and implement it in PHP with advanced custom fields.
The custom image size is 1000px by 1000px.
In an attempt to trouble shoot and narrow down the issue, I amended the default WP size of 'medium' to also be 1000px by 1000px.
In the code below, the top image which uses this default 'medium' size renders perfectly on the website using the correct image but the second does not, it just displays the full size image.
I can't work out what is wrong with my custom image code given that it seemingly should be very straight forward.
<!-- THIS WORKS -->
<?php
$top_image = get_field('top_animated_image_1');
?>
<div class="upper-image">
<?php $top_animated_image_1 = get_field( 'top_animated_image_1' ); ?>
<?php $size = 'medium'; ?>
<?php if ( $top_animated_image_1 ) : ?>
<?php echo wp_get_attachment_image( $top_animated_image_1, $size ); ?>
<?php endif; ?>
</div>
<!-- THIS DOES NOT -->
<?php
$lower_image = get_field('lower_animated_image_2');
?>
<div class="lower-image">
<?php $lower_animated_image_2 = get_field( 'lower_animated_image_2' ); ?>
<?php $size = 'home_portrait'; ?>
<?php if ( $lower_animated_image_2 ) : ?>
<?php echo wp_get_attachment_image( $lower_animated_image_2, $size ); ?>
<?php endif; ?>
</div>
I got this working in the end by changing it to
// Make sure featured images are enabled
add_theme_support( 'post-thumbnails' );
// Add featured image sizes
add_image_size( 'home_portrait', 1000, 1000, false ); // width, height, crop
// Register the three useful image sizes for use in Add Media modal
add_filter( 'image_size_names_choose', 'wpshout_custom_sizes' );
function wpshout_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'home_portrait' => __( 'Home Portrait' ),
) );
though I am still not sure why the first did not work

Displaying specific thumbnail size in single.php

Currently I'm building a Wordpress theme and I'm trying to display a specific image size, which is cropped in my single.php, and thus on individual post pages and not having any luck.
Here's my functions.php:
add_theme_support( 'post-thumbnails' );
add_image_size('new-thumbnail-size',600,340, true);
Here's my single.php:
<?php if( get_the_post_thumbnail() ) : ?>
<div class = 'postImgCon'>
<div class="feat-img">
<?php the_post_thumbnail('new-thumbnail-size'); ?>
</div>
</div>
<?php endif; ?>
Any ideas?
You're using the correct functions to declare support for post thumbnails and add an image size but you need to do so inside the after_setup_theme hook.
Inside functions.php change:
add_theme_support( 'post-thumbnails' );
add_image_size('new-thumbnail-size',600,340, true);
To:
function wpse_setup_theme() {
add_theme_support( 'post-thumbnails' );
add_image_size( 'new-thumbnail-size', 600, 340, true );
}
add_action( 'after_setup_theme', 'wpse_setup_theme' );
Also you're using the wrong function to check if a post has a thumbnail. It should still work but here's the correct approach.
Inside single.php change:
<?php if( get_the_post_thumbnail() ) : ?>
To:
<?php if ( has_post_thumbnail() ) : ?>
Finally you need to be aware that any images you've already uploaded won't have been cropped to 600 x 340 so you won't get the output you're expecting. You need to regenerate your existing images. Take a look at the following plugin for that: https://wordpress.org/plugins/regenerate-thumbnails/
Try this
....
<div class="feat-img">
<?php echo the_post_thumbnail($page->ID, "new-thumbnail-size'); ?>
....

WP How do I customize a specific thumbnail size using CSS class

I've tried add_image_size to do my custom thumbnail resize but for some reason it won't stand the thumbnail being 220 x 220 and it will change the height to 167 x, for this I've been trying to do a CSS-based solution instead, which I suppose to work perfectly.
My thumbnail code
<?php if ( ! post_password_required() && ! is_attachment() ) :
the_post_thumbnail();
endif; ?>
the css class I need help applying to the thumbnail code above:
.imgclass{
height: 220px;
width: 220px;
}
Thanks to all the coders out there!
You can find thumbnail url & give css to that
<?php $url = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>
<img src="<?php echo $url; ?>" class="img_thumb"/>
You will need to specify what image size you are using as the thumbnail.
<?php if ( ! post_password_required() && ! is_attachment() ) :
the_post_thumbnail('IMAGE SIZE NAME');
endif; ?>
Alternatively, you can completely reset the base thumbnail size like so:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 220, 220 );
<?php if ( ! post_password_required() && ! is_attachment() ) :
$thumb_attrs = array( 'class' => "imgclass") ;
the_post_thumbnail($thumb_attrs);
endif; ?>
Should work.

Show featured image and excerpt of specific page on home page wordpress

I want to display featured image and excerpt of ie. ABOUT page on my home page. Is it possible to do this with pages not posts only?
found the answer in the meantime for the excerpt, now I need only featured image
add new function to functions.php:
//Display page excerpts
add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
and call the function in front-page.php>
<?php echo get_the_excerpt(); ?>
<?php
query_posts("page_id=2");
while ( have_posts() ) : the_post()
?>
<h1>Why US?</h1>
<?php the_excerpt(); ?>
<?php
endwhile;
wp_reset_query();
?>
For the featured image, you need :
1 - to modify your function, to add also thumbnail support
add_action( 'init', 'my_extend-page_functions' );
function my_extend-page_functions() {
add_post_type_support( 'page', array('excerpt', 'thumbnail' );
}
(Have a look on the codex page of all you can add http://codex.wordpress.org/Function_Reference/add_post_type_support )
2- on the front-page, you can use the_post_thumbnail()
http://codex.wordpress.org/Function_Reference/the_post_thumbnail

thumbnail slider size is not applied correctly codex:add_image_size wordpress

Have a problem i upload one image with 400px 300px
functions.php and I have defined the following
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );//Agrega soporte
add_image_size( 'slider-thumbnail', 940, 310, true ); // Slider thumbnail
}
header.php
<?php query_posts('' );
while ( have_posts() ) : the_post(); ?>
<?php the_post_thumbnail('slider-thumbnail'); ?>
<?php endwhile; wp_reset_query(); ?>
But when he grabs the picture appears to scale and repeated not being adjusted to the size you set it, I want to engage me esque size 940px to 310px but defined to deform me why this happens?

Resources