Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1185924
    GATHH
    Participant

    Hi there,

    When I upload a new image to a post, the following sizes are generated:
    100×67, 150×150, 300×200, 500×334, 500×500, 500×587, 768×512, 862×482, 862×575, 880×500

    Currently, X uses the following image size for my featured posts:
    862×575

    How can I force X to use this size instead:
    880×500

    Or better yet, where can I change the size of the generated images? I.e. Instead of having x generate this size 862×575, how can we change it to generate this size: 900×600

    Thanks.

    #1186016
    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! What you are trying to accomplish requires a template customization, we would like to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    After the child theme is set up, please add the following code in your child theme’s functions.php file

    // Custom featured image displaying the large size image dimension on archive pages
    // =============================================================================
    function x_featured_image( $cropped = '' ) {
    
      $stack     = x_get_stack();
      $fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;
    
      if ( has_post_thumbnail() ) {
    
        $thumb = get_the_post_thumbnail( NULL, 'large', NULL );
    
        switch ( is_singular() ) {
          case true:
            $get_description = get_post(get_post_thumbnail_id())->post_excerpt; 
            var_dump($get_description);
            if(!empty($get_description)){
              //If description is not empty show the div echo '<div class="img-caption">' . $get_description . '</div>'; 
            }
    
            printf( '<div class="entry-thumb">%s</div>', $thumb );
            break;
          case false:
            printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
              esc_url( get_permalink() ),
              esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
              $thumb
            );
            break;
        }
    
      }
    
    }
    // =============================================================================

    You can change to medium, large or full image size in this line:
    $thumb = get_the_post_thumbnail( NULL, 'full', NULL );

    Hope this helps. Please let us know how it goes.

    #1186021
    Paul R
    Moderator

    Hi,

    Please do the following.

    1. Add your image size by adding the code below in your child theme functions.php file

    
    add_image_size( 'gathh-size', 220, 180 );
    

    2. Install, activate and Run Force regenerate thumbnails plugin

    Force Regenerate Thumbnails

    3. Change featured image function to pull your new image size by adding this in your child theme’s functions.php file.

    
    function x_featured_image( $cropped = '' ) {
    
        $stack     = x_get_stack();
        $fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;
    
        if ( has_post_thumbnail() ) {
    
          if ( $cropped == 'cropped' ) {
            if ( $fullwidth ) {
              $thumb = get_the_post_thumbnail( NULL, 'entry-cropped-fullwidth', NULL );
            } else {
              $thumb = get_the_post_thumbnail( NULL, 'entry-cropped', NULL );
            }
          } else {
            if ( $fullwidth ) {
              $thumb = get_the_post_thumbnail( NULL, 'entry-fullwidth', NULL );
            } else {
              $thumb = get_the_post_thumbnail( NULL, 'entry', NULL );
            }
          }
          
          $post_thumb = get_the_post_thumbnail( NULL, 'gathh-size', NULL );
    
          switch ( is_singular() ) {
            case true:
              printf( '<div class="entry-thumb">%s</div>',$post_thumb );
              break;
            case false:
              printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
                esc_url( get_permalink() ),
                esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
                $thumb
              );
              break;
          }
    
        }
    
      }
    

    Hope that helps.

    #1186222
    GATHH
    Participant

    Hi Rue Nel,

    Thanks for your reply. This worked well. However, now it shows string(0) “” above the photo. See screenshot attached.
    What do I need to change in the code to remove this?
    Thanks.

    #1186346
    Paul R
    Moderator

    Hi,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1187402
    GATHH
    Participant
    This reply has been marked as private.
    #1187500
    Rue Nel
    Moderator

    Hello There,

    Thank you for the very detailed information. I have logged in and have already fixed the issue. It was just a var_dump() function in the given code. Nothing to worry about. It is already gone.

    Is this what you are looking for? Please confirm if this has resolved the issue.

    Thank you very much.

    #1187589
    GATHH
    Participant

    Hi Rue,
    Thanks a lot. Really appreciate your help. This has resolved the issue.
    You guys rock!

    #1187603
    Paul R
    Moderator

    You’re welcome! 🙂

  • <script> jQuery(function($){ $("#no-reply-1185924 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>