<div class="post-item portfolio-item">
    <?php
    $category = get_the_terms( $post, 'portfolio_cat' );
    if (is_array( $category )) {
        $firstCategory = $category[0];
    }
    if(!empty($firstCategory)):?>
    <a href="<?php echo get_term_link($firstCategory->term_id,'portfolio_cat'); ?>" class="post-item-cat"><?php echo $firstCategory->name; ?></a>
    <?php endif;?>

    <div class="post-item-image">
        <a href="<?php the_permalink() ?>">
            <?php if (has_post_thumbnail()): the_post_thumbnail('medium');
            else:
                echo "<img src='" . esc_url(get_template_directory_uri() . '/images/default.jpg') . "' alt='image'>";
            endif; ?>
        </a>
    </div>
    <div class="post-item-content">
        <a href="<?php the_permalink() ?>" class="title"><div><?php the_title(); ?></div></a>
    </div>
    <a href="<?php the_permalink() ?>" class="post-overly-icon"><i class="icon-arrow-right"></i></a>
</div>
