Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this.

    <?php
      query_posts(array( 
        'post_type' => 'post',
        'showposts' => 5
      )); 
    
      $i = 0;
      while ( have_posts() ) :
      the_post();
      $i++;
    ?>
      <a class="card" href="<?= get_permalink() ?>">
    
        <?php if ($i === 1) : ?>
          <div class="card__meta"><?= get_the_category()[0]->cat_name ?></div>
          <div class="card__media">
            <img src="<?php the_post_thumbnail_url('medium'); ?>">
          </div>
          <div class="card__title"><?php the_title(); ?></div>
        <?php else : ?>
          <div class="card__title"><?php the_title(); ?></div>
        <?php endif; ?>
    
      </a>
    <?php endwhile; ?>
    • This reply was modified 7 years, 9 months ago by bluder.
    • This reply was modified 7 years, 9 months ago by bluder.
    Thread Starter bluder

    (@bluder)

    I solved this using the wp_get_attachment_metadata filter. Removed the suffixes -{$width}x{$height} for all sizes, and put the prefix at the beginning of the file name, instead in the beginning URL.

    function attachment_metadata_filter($data) {
      foreach ($data['sizes'] as $key => $size) {
        $width = $size['width'];
        $height = $size['height'];
    
        $fileNoSuffix = str_replace("-{$width}x{$height}", '', $data['sizes'][$key]['file']); // remove suffix
        $data['sizes'][$key]['file'] = "{$width}x{$height}/" . $fileNoSuffix; // add prefix
      }
    
      return $data;
    }
    add_filter('wp_get_attachment_metadata', 'attachment_metadata_filter');
    • This reply was modified 7 years, 9 months ago by bluder.
    • This reply was modified 7 years, 9 months ago by bluder.
Viewing 2 replies - 1 through 2 (of 2 total)