Support » Fixing WordPress » Featured Image does not hard-crop

  • Hey guys,

    First things first: I am a complete noob when it comes to WP and PHP. I have to say though, that I never really got my head around PHP.

    My problem is (and i tried this for days with countless different approaches): I’d like the excerpts of posts I made to show those featured images and hard-crop those.

    I’m working with a child theme of Thematic, installed under WP 3.4.1 locally in a test environment using MAMP, running PHP 5.3.6.

    The code I use is located in the theme-child-folder’s functions.php file. The code does work, regarding the shortening of excerpts and showing a ‘read more’ link. It also shows a photo, however, what I didn’t accomplish is to hard-crop the photo. It always just shows the complete photo, scaled down the maximum dimensions, defined in the code below.

    //use excerpts on home page
    function child_content($content) {
    if ( is_home() ) {
    $content = ‘excerpt’;
    return $content;
    add_filter(‘thematic_content’, ‘child_content’);

    // excerpt read more links- adds a read more link to every excerpt- including manual ones
    function all_excerpts_get_more_link($post_excerpt) {

    return $post_excerpt . ‘<span class=”readmore”>ID) . ‘”>’ . ‘Read more’ . ‘</span>’;
    add_filter(‘wp_trim_excerpt’, ‘all_excerpts_get_more_link’);

    // change […] to … or whatever
    function excerpt_ellipse($text) {
    return str_replace(‘[…]’, ‘…’, $text);
    add_filter(‘get_the_excerpt’, ‘excerpt_ellipse’);

    //change length of excerpt
    function new_excerpt_length($length) {
    return 40;
    add_filter(‘excerpt_length’, ‘new_excerpt_length’);

    function child_post_thumb() {
    return array(200,200);

    Thanks guys…

Viewing 1 replies (of 1 total)
  • I don’t know what I’m doing wrong, but I tried a different code yet again. However, changing “set_post_thumbnail_size( 300, 200, true );” from ‘true’ to ‘false’ doesn’t change a thing. According to WP codex, it is supposed to change the photo from hard-crop to soft-crop mode. I uploaded a new photo to check, if this piece of code has any effect at all. It doesn’t. Other people have reported simular issues with “set_post_thumbnail_size’. All I want is for the photos of my excerpts to all look the same. I’ve been messing around with this for days, it can’t be that difficult?!

    // Add filter to the_content
    add_filter(‘the_content’, ‘my_excerpts’);

    function my_excerpts($content = false) {

    // If this is the home page, an archive, or search results
    if(is_front_page() || is_archive() || is_search() || is_category()) :
    global $post;
    $content = $post->post_excerpt;

    // If an excerpt is set in the Optional Excerpt box
    if($content) :
    $content = apply_filters(‘the_excerpt’, $content);

    // If no excerpt is set
    else :

    $content = $post->post_content;
    $content = strip_shortcodes($content);
    $content = str_replace(‘]]>’, ‘]]>’, $content);
    $content = strip_tags($content);
    $excerpt_length = 55;
    $words = explode(‘ ‘, $content, $excerpt_length + 1);
    if(count($words) > $excerpt_length) :
    array_push($words, ‘ Weiterlesen‘);
    $content = implode(‘ ‘, $words);
    $content = ‘<p>’ . $content . ‘</p>’;


    // Make sure to return the content
    return $content;

    //* First we will add the thumbnail feature *//
    add_theme_support( ‘post-thumbnails’, array( ‘post’ ) ); // Add it for posts
    set_post_thumbnail_size( 300, 200, true ); // hard crop mode

    //* To create our own loop we have to get rid of thematic index loop first.*//
    function remove_index_loop() {
    remove_action(‘thematic_indexloop’, ‘thematic_index_loop’);
    add_action(‘init’, ‘remove_index_loop’);

    // Now we will create our own loop.
    function thumb_index_loop(){
    while ( have_posts() ) : the_post() // Start the loop:
    // This is just what we decide to show in each post ?>
    <div id=”post-<?php the_ID() ?>”>
    <div class=”hentry”>
    <?php thematic_postheader(); ?>
    <?php the_post_thumbnail(); // we just called for the thumbnail ?>
    <?php the_content(); ?>

    <?php thematic_postfooter(); ?>
    </div><!– .post –>


    endwhile; // loop done, go back up
    // And in the end activate the new loop.
    add_action(‘thematic_indexloop’, ‘thumb_index_loop’);

Viewing 1 replies (of 1 total)
  • The topic ‘Featured Image does not hard-crop’ is closed to new replies.