我正在为我的所有帖子添加社交分享按钮。有没有一种方法可以将代码放入函数中,这样当我将社交共享按钮放在某个地方时,我就可以调用该函数?
这是社交共享按钮代码。。。
<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();?>&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\') . \'&p=\' .get_permalink().\'&t=\'.get_the_title().\'"onclick=\\\'window.open(this.href,"bloglovin_like","height=320,width=480,toolbar=0,location=0,menubar=0,scrollbars=0,status=0"); 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>
这是我的正面。php我想把社交分享按钮放在每篇文章的阅读更多按钮之前。然而,如果我把社会共享代码放在每一个之前,我将不得不在代码中粘贴很多次。所以我想知道是否有更有效的方法来做到这一点?(我知道我在这段代码中已经有了一些函数-这是因为我在创建这段代码时得到了一些帮助-我对这段代码还是新手,我自己也不太清楚如何做到这一点)<?php
/*
* Template Name:
*/
get_header();
get_template_part (\'inc/carousel\');
$the_query = new WP_Query( [
\'posts_per_page\' => 14,
\'paged\' => 1
] );
<div id="ajax">
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 every 7th post after... ?>
<article <?php post_class( \'col-md-12\' ); ?>>
<?php the_post_thumbnail(\'large-thumbnail\'); ?>
<h2><a class="post-title" href="<?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="<?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="<?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="<?php the_permalink(); ?>">Read more</a>
<?php comments_popup_link (\'No Comments\', \'1 Comment\', \'% Comments\', \'comment-count\', \'none\'); ?>
</article>
<?php
}
$i++;
}
wp_reset_postdata();
</div>
}
else {
echo \'<p>Sorry, no posts matched your criteria.</p>\';
}
<?php load_more_button(); ?>
get_footer();
这是头版的布局