简体   繁体   English

如何添加社交分享按钮?

[英]How do I add social sharing buttons?

I am on Wordpress and I can easily add a plugin, but that increases load time, looks common and old.我在 Wordpress 上,我可以轻松添加插件,但这会增加加载时间,看起来很普通且陈旧。

I am using the Brook theme, which a minimal theme.我正在使用 Brook 主题,这是一个最小的主题。 ( http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/ ) ( http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/ )

If you notice, only end at the blog I have my sharing options, Such as Facebook, Linkedin, Twitter.如果你注意到,只在博客结束我有我的分享选项,比如 Facebook、Linkedin、Twitter。

Can I enable this in the Sidebar widget?我可以在侧边栏小部件中启用它吗? I contacted my theme author and they said to me,我联系了我的主题作者,他们对我说,

"Our social-sharing links are built in brook/share_block.php. You could try creating a new custom widget, and use the code from share_block.php. Alternatively, you could use a Text Widget, and input directly html code for sharing. By using the markup and classes as we did, you should be able to get the same style." “我们的社交分享链接建立在brook/share_block.php。你可以尝试创建一个新的自定义小部件,并使用share_block.php中的代码。或者,你可以使用一个文本小部件,并直接输入html代码进行分享。通过像我们一样使用标记和类,您应该能够获得相同的样式。”

Here's my that php file.这是我的那个 php 文件。 I tried various methods but it did not work.我尝试了各种方法,但没有奏效。 Guess everything is wrong.估计一切都错了。

Can you all help?大家可以帮忙吗?

<?php

$theme_settings = brook_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', 'brook' ); ?>" class="social-nav__link js-skip-ajax" href="mailto:?subject=<?php echo ( rawurlencode( get_the_title() ) ); ?>&amp;body=<?php echo ( rawurlencode ( $share_excerpt . ' ' . get_the_permalink() ) ); ?>">
                    <?php _e( 'Email', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_facebook'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Facebook', 'brook' ); ?>" 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', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_twitter'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Twitter', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank"  href="http://twitter.com/intent/tweet?text=<?php echo( rawurlencode( get_the_title() ) ); ?>&amp;url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
                    <?php _e( 'Twitter', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_pinterest'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Pinterest', 'brook' ); ?>" 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() ) ); ?>&amp;media=<?php echo ( rawurlencode( $share_image_portrait ) ); ?>&amp;description=<?php echo( rawurlencode( get_the_title() ) ); ?>">
                    <?php _e( 'Pinterest', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

        <?php if( $theme_settings['sharing_google'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'Google+', 'brook' ); ?>" 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+', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>
        <?php if( $theme_settings['sharing_linkedin'] ): ?>
            <li class="social-nav__item">
                <a title="<?php _e( 'LinkedIn', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&amp;title=<?php echo( rawurlencode( get_the_title() ) ); ?>&amp;summary=<?php echo ( rawurlencode ( $share_excerpt ) );?>&amp;source=<?php echo ( rawurlencode( get_bloginfo('name') ) );?>">
                    <?php _e( 'LinkedIn', 'brook' ); ?>
                </a>
            </li>
        <?php endif; ?>

    </ul>
</div>

尝试社交分享插件并放置短代码。

Well What I suggest you which is the easiest solution is first install a plugin from this link https://wordpress.org/plugins/php-code-widget/那么我建议你这是最简单的解决方案是首先从这个链接https://wordpress.org/plugins/php-code-widget/安装一个插件
It ia a plugin when you activate it, it creates a widget in which you can put your all php code from your required file.它是一个插件,当您激活它时,它会创建一个小部件,您可以在其中放置所需文件中的所有 php 代码。 As far as the styling is concerned you can add the relevant styling to main css file of your Brook theme.就样式而言,您可以将相关样式添加到 Brook 主题的主 css 文件中。 I hope it helps....我希望它有帮助......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM