dongpao1921 2015-10-14 04:58
浏览 223
已采纳

如何添加社交分享按钮?

I am on Wordpress and I can easily add a plugin, but that increases load time, looks common and old.

I am using the Brook theme, which a minimal theme. (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.

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."

Here's my that php file. 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>
  • 写回答

2条回答 默认 最新

  • doujiena0025 2015-10-14 05:27
    关注

    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/
    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. As far as the styling is concerned you can add the relevant styling to main css file of your Brook theme. I hope it helps....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行