dongpao1921 2015-10-13 20: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-13 21: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条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部