如何添加社交分享按钮?
我在Wordpress上,我可以很容易地添加一个插件,但这会增加加载时间,看起来很普遍,也很古老。如何添加社交分享按钮?
我使用的是*主题,它是一个最小的主题。 (http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/)
如果您注意,只能在博客上结束我有我的分享选项,例如Facebook,Linkedin,Twitter。
我可以在侧边栏小部件中启用它吗?我联系了我的主题笔者,他们对我说,
“我们共享的社会链接都建在小溪/ share_block.php。你 可以尝试创建一个新的自定义窗口小部件,并从 share_block使用的代码。 php。或者,你可以使用Text Widget,并直接输入 用于分享的html代码。通过使用 所做的标记和类,你应该能够获得相同的风格。
这是我的那个php文件。我尝试了各种方法,但没有奏效。猜猜一切都是错误的。
你们能帮忙吗?
<?php
$theme_settings = *_theme_settings();
if(has_post_thumbnail()){
$share_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'xxl');
$share_image = $share_image[0];
$share_image_portrait = wp_get_attachment_image_src(get_post_thumbnail_id(), 'portrait-m');
$share_image_portrait = $share_image_portrait[0];
}else{
$share_image = '';
$share_image_portrait = '';
}
$share_excerpt = strip_tags(get_the_excerpt(), '<b><i><strong><a>');
?>
<div class="social-nav social-nav--titles">
<ul class="social-nav__items">
<?php if($theme_settings['sharing_email']): ?>
<li class="social-nav__item">
<a title="<?php _e('Email', '*'); ?>" class="social-nav__link js-skip-ajax" href="mailto:?subject=<?php echo (rawurlencode(get_the_title())); ?>&body=<?php echo (rawurlencode ($share_excerpt . ' ' . get_the_permalink())); ?>">
<?php _e('Email', '*'); ?>
</a>
</li>
<?php endif; ?>
<?php if($theme_settings['sharing_facebook']): ?>
<li class="social-nav__item">
<a title="<?php _e('Facebook', '*'); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.facebook.com/sharer.php?u=<?php echo(rawurlencode(get_the_permalink())); ?>">
<?php _e('Facebook', '*'); ?>
</a>
</li>
<?php endif; ?>
<?php if($theme_settings['sharing_twitter']): ?>
<li class="social-nav__item">
<a title="<?php _e('Twitter', '*'); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://twitter.com/intent/tweet?text=<?php echo(rawurlencode(get_the_title())); ?>&url=<?php echo(rawurlencode(get_the_permalink())); ?>">
<?php _e('Twitter', '*'); ?>
</a>
</li>
<?php endif; ?>
<?php if($theme_settings['sharing_pinterest']): ?>
<li class="social-nav__item">
<a title="<?php _e('Pinterest', '*'); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php echo(rawurlencode(get_the_permalink())); ?>&media=<?php echo (rawurlencode($share_image_portrait)); ?>&description=<?php echo(rawurlencode(get_the_title())); ?>">
<?php _e('Pinterest', '*'); ?>
</a>
</li>
<?php endif; ?>
<?php if($theme_settings['sharing_google']): ?>
<li class="social-nav__item">
<a title="<?php _e('Google+', '*'); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="https://plus.google.com/share?url=<?php echo(rawurlencode(get_the_permalink())); ?>">
<?php _e('Google+', '*'); ?>
</a>
</li>
<?php endif; ?>
<?php if($theme_settings['sharing_linkedin']): ?>
<li class="social-nav__item">
<a title="<?php _e('LinkedIn', '*'); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo(rawurlencode(get_the_permalink())); ?>&title=<?php echo(rawurlencode(get_the_title())); ?>&summary=<?php echo (rawurlencode ($share_excerpt));?>&source=<?php echo (rawurlencode(get_bloginfo('name')));?>">
<?php _e('LinkedIn', '*'); ?>
</a>
</li>
<?php endif; ?>
</ul>
</div>
我建议你清楚什么是最简单的解决方案是第一个从这个链接https://wordpress.org/plugins/php-code-widget/
据保险业监督,当你激活插件安装一个插件,它会创建一个小部件,你可以把你所有的PHP代码从您需要的文件。就样式而言,您可以将相关样式添加到*主题的主要CSS文件中。我希望它可以帮助....
非常感谢你*!你能告诉哪个PHP要添加吗? (我对PHP非常陌生)。 –
来自你的share_block.php文件。 – 2015-10-14 05:33:58
非常感谢!奇迹般有效!它超级棒。检查我的网站。 http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/我所要做的就是编辑一下这个附件。作品。谢谢。 :) –
尝试社交分享插件,并把短代码。
什么是短代码? –
你有没有尝试创建一个短代码,将回显上述所有HTML代码? https://codex.wordpress.org/Shortcode_API – CDrosos