How to make a new function that includes a template

Add your share button html to a template file in your theme:

your-theme/share-buttons.php

<a href="http://twitter.com/home/?status=<?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" title="Tweet this!"><img src="http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-twitter.png"></a>

<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php the_title(); ?>" target="_blank" title="Share on Facebook."><img src="http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-facebook.png"></a>

<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $url; ?>" target="_blank"><img src="http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-pinterest.png"></a>

<a href="http://www.bloglovin.com/e/?b=' .get_bloginfo('wpurl') . '&#038;p=' .get_permalink().'&#038;t=".get_the_title().""onclick=\'window.open(this.href,&quot;bloglovin_like&quot;,&quot;height=320,width=480,toolbar=0,location=0,menubar=0,scrollbars=0,status=0&quot;); return false;\'--><img style="margin: 10px 0 10px 0; border: 0; padding: 0;" src="http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-bloglovin-1.png" alt="" />

<a href="http://twitter.com/home/?status=<?php the_title(); ?> - <?php the_permalink(); ?>" target="_blank" title="Tweet this!"><img src="http://localhost:8888/wordpress/wp-content/uploads/2016/12/social-shopping.png"></a>

Use get_template_part() to include the template in the appropriate locations.

get_template_part( 'share-buttons' );

Edit: Here’s an updated version of the template code which should address some issues in the original. It includes the share buttons template part too:

<?php
/*
 * Template Name:
 */

get_header();
get_template_part ('inc/carousel');

$the_query = new WP_Query( [
    'posts_per_page' => 14,
    'paged' => 1
] );

if ( $the_query->have_posts() ) {
    $i = 0;
    while ( $the_query->have_posts() ) { $the_query->the_post();

        if ( $i % 7 === 0 ) { // Large post: on the first iteration and after every block of 6 posts... ?>

            <article <?php post_class( 'col-md-12' ); ?>>
                <?php the_post_thumbnail('large-thumbnail'); ?>
                <h2><a class="post-title" href="https://wordpress.stackexchange.com/questions/248745/<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p>
                <?php get_template_part( 'share-buttons' ); ?>
                <a class="moretext" href="https://wordpress.stackexchange.com/questions/248745/<?php the_permalink(); ?>">Read more</a>
                <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?>
            </article><?php

        } else { // Small posts ?>

            <article <?php post_class( 'col-md-4' ); ?>>
                <?php the_post_thumbnail( 'medium-thumbnail' ); ?>
                <h2><a class="post-title" href="https://wordpress.stackexchange.com/questions/248745/<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p class="post-excerpt"><?php echo get_the_excerpt(); ?></p>
                <?php get_template_part( 'share-buttons' ); ?>
                <a class="moretext" href="https://wordpress.stackexchange.com/questions/248745/<?php the_permalink(); ?>">Read more</a>
                <?php comments_popup_link ('No Comments', '1 Comment', '% Comments', 'comment-count', 'none'); ?>
            </article><?php 
        }
        $i++;
    }
    wp_reset_postdata();
}
else {
    echo '<p>Sorry, no posts matched your criteria.</p>';
}

get_footer();