Viewing 15 replies - 1 through 15 (of 29 total)
  • First, register new image size, assuming there’s no size for that yet.

    add_image_size( 'front-feature', 600, 300 );

    Look in whatever front page template that is being used for your front ( it’s most likely to be index.php ), find the call to the_post_thumbnail() inside the loop, and replace it with this.

    if ( is_sticky ( $post->ID ) ) {
    	the_post_thumbnail('front-feature');
    } else {
    	the_post_thumbnail();
    }

    Post marked as “sticky” will be using this image size, then in your style.css make use of .sticky to style this post’s content as you like.

    Image already uploaed will not get the newly registered size, you have to either delete and re-upload or use Regenerate Thumbnail plugin to auto resize all the already uploaded ones.

    Also, to avoid too many cropped images cluttering up in upload folder, just go to Settings > Media and set Medium size to 600×300 and use the_post_thumbnail('medium') instead, no need to register new size.

    Thread Starter bettyjohnson

    (@bettyjohnson)

    Where should I start pasting in the code you gave me?

    <?php if(has_post_thumbnail()) : ?>
    
    	<div class="thumbnail">
    		<?php the_post_thumbnail((array(150,150)), array( 'title' => get_the_title() )); ?>
    	</div>
    
    	<div class="post-content">

    Just this one line

    <?php the_post_thumbnail((array(150,150)), array( 'title' => get_the_title() )); ?>

    replaced with

    <?php
    	if ( is_sticky ( $post->ID ) ) {
    		the_post_thumbnail('front-feature', array( 'title' => get_the_title() ));
    	} else {
    		the_post_thumbnail((array(150,150)), array( 'title' => get_the_title() ));
    	}
    ?>
    Thread Starter bettyjohnson

    (@bettyjohnson)

    @paulwpxp I did adjust all codes, but nothing changed.

    Can you please take a look at the website?

    The text “add_image_size( ‘front-feature’, 600, 300 );” is printed out in the page, this indicates that you put this line in the template, right ?

    That is a function to register image size, it must be in theme’s setup function in functions.php.

    Please be aware that edting php file on a live site could be done only if you know what you are doing. So it’s better to direct this to the person who built this theme for you.

    At the beginning I thought that you coded it up yourself, but anyway, always have a backup.

    In the functions.php file of most WP theme, you would see something like this at the very beginning.

    add_action( 'after_setup_theme', 'mytheme_setup' );
    
    function mytheme_setup() {
    	// few other things in here
    	add_theme_support( 'post-thumbnails' );
    	add_image_size( 'front-feature', 600, 300 );
    	// few other things in here
    }

    The add_theme_support( 'post-thumbnails' ); should already be there, just add in the add_image_size() under it, like shown above.

    Thread Starter bettyjohnson

    (@bettyjohnson)

    I normally have the site “under construction” during code changing, but in order for you to see it, I disabled the construction view.

    However, I have changed all the codes (backup’s available on my end) you gave me, and started coding the .sticky in style.css but nothing happened!???

    There is this code in functions.php, do I have to change it up a bit, since I want my last post to have the featured image in 600×300?

    set_post_thumbnail_size( 150, 150, true ); // Normal post thumbnails, hard crop mode

    But keep the excerpt, below the image.

    Post marked as “sticky” will be using this image size, then in your style.css make use of .sticky to style this post’s content as you like.

    There is no sticky class output in the post section. So did you mark that post as sticky yet ?

    Image already uploaed will not get the newly registered size, you have to either delete and re-upload or use Regenerate Thumbnail plugin to auto resize all the already uploaded ones.

    There is non existence of imagefilename-600×300.png version of the thumbnail image in your top most post. So did you delete and re-upload or use Regenerate Thumbnail plugin yet ?

    There is nothing in functions.php that needs to change.

    But you need to add in add_image_size( 'front-feature', 600, 300 );

    Thread Starter bettyjohnson

    (@bettyjohnson)

    I added the extra image size, working on Regenerate Thumbnails at the moment.

    Sorry for all the trouble, I am a new-be when it comes to coding!

    Will I have to mark each post manually as sticky (and if so, how do I have to do that?), or is there a way to have always the current post as featured?

    Going with sticky will give us option to choose any post to be featured.

    But yes, we can target only first post in the loop instead of sticky. It just needs a few more lines of code, but let’s make sure that we got this working properly first.

    Thread Starter bettyjohnson

    (@bettyjohnson)

    Ok, I am done regenerating the images with Regenerate Thumbnails, there are no visible changes to see so far!

    Still, there is no .sticky class, as if there is no post marked as sticky.

    there is no existence of imagename-600×300.png version of the image, this indicates that the add_image_size hasn’t been put in place, or Regen didn’t work.

    You can test if the add_image_size is working properly by making a new test post and upload a new image to it and set as Feature Image.

    Thread Starter bettyjohnson

    (@bettyjohnson)

    Ok, I will do that

    Thread Starter bettyjohnson

    (@bettyjohnson)

    Sorry for the delay!

    I posted a post and tried to upload the image as Medium 600×300, however under Settings > Media the Medium size I entered (600 x 300) in functions.php didn’t take over in the “Insert Media uploader”. It still shows as 300×300.

    Any suggestions?

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘How to create a featured post?’ is closed to new replies.