Complex Custom Loop with Includes

Here are some optimization suggestions for the code:

Refactor the code structure: Currently, the code is using multiple if statements to determine which template to display for each portfolio item. This can be refactored to use a single switch statement. This will make the code more readable and easier to maintain.

Remove redundant code: The $paged variable is defined twice in the $args array, so it can be removed from the second definition.

Improve pagination: Currently, the pagination is done by checking if $portfolio_loop->max_num_pages is greater than 1. A better approach would be to use the paginate_links() function provided by WordPress to display the pagination links.

Remove unused variables: The $customClass variable is defined but not used, so it can be removed.

Replace magic numbers with constants: Currently, the code is using magic numbers (e.g., 7, 11, 15, 99) to determine the layout for each portfolio item. These values should be replaced with constants to make the code more readable and easier to maintain.

    <?php 
  // GLOBAL VARIABLES
  global $count;
  global $customClass;
?> 
<article id="post-<?php the_ID(); ?>" <?php post_class("$customClass $count m-b-20--sm m-b-75--lg"); ?>>
  <!-- COMING SOON -->
  <?php if(has_term('coming-soon', 'portfolio_status')) {
    get_template_part('template-parts/portfolio/portfolio', 'soon-badge');
  } ?>
  <!-- COMING SOON --> TEST: <?php echo $customClass; ?>
  <figure class="lazyload portfolio__image m-b-30--md m-b-20--sm"> 
    <?php if(!has_term('coming-soon', 'portfolio_status')) { ?>
      <a href="<?php echo get_permalink(); ?>">  
    <?php } 
      if ($customClass === "landscape") {
        echo the_post_thumbnail('portfolio-landscape');
      }
      elseif ($customClass === "portrait") {
        echo the_post_thumbnail('portfolio-portrait');
      }
    ?>  
    <?php if(!has_term('coming-soon', 'portfolio_status')) { ?>
      </a>
    <?php } ?>    
  </figure>
  <span class="block meta"><?php echo strip_tags(get_the_term_list( $post->ID, 'portfolio_categories', ' ',', ')); ?></span>
  <h2 class="h4 portfolio__title">
    <?php if(!has_term('coming-soon', 'portfolio_status')) { ?>
      <a href="<?php echo get_permalink(); ?>">  
    <?php } ?>     
    <?php the_title(); ?>
    <?php if(!has_term('coming-soon', 'portfolio_status')) { ?>
      </a>
    <?php } ?>
  </h2>
  <div class="portfolio__excerpt m-t-10"><?php the_excerpt(); ?></div>
  <?php get_template_part('template-parts/portfolio/portfolio', 'tags'); ?>
</article>