首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将我的网站内容发布到wordpress和blogger网站

如何将我的网站内容发布到wordpress和blogger网站
EN

Stack Overflow用户
提问于 2015-10-31 13:08:41
回答 1查看 60关注 0票数 0

如何在没有任何第三方工具的情况下,将我的网站内容分享给wordpress博客和谷歌的博客,比如facebook分享、twitter分享。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-10-31 16:46:36

  • 第1步:

转到主题的function.php文件并粘贴到下面的代码。这将在bottom of the post上添加共享按钮

代码语言:javascript
复制
function crunchify_social_sharing_buttons($content) {
    if(is_singular() || is_home()){

        // Get current page URL 
        $crunchifyURL = get_permalink();

        // Get current page title
        $crunchifyTitle = str_replace( ' ', '%20', get_the_title());

        // Get Post Thumbnail for pinterest
        $crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );

        // Construct sharing URL without using any script
        $twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
        $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
        $googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
        $bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&text='.$crunchifyTitle;

        // Based on popular demand added Pinterest too
        $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;

        // Add sharing button at the end of page/page content
        $content .= '<div class="crunchify-social">';
        $content .= '<h5>SHARE ON</h5> <a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
        $content .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
        $content .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
        $content .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
        $content .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
        $content .= '</div>';

        return $content;
    }else{
        // if not a post/page then don't include sharing button
        return $content;
    }
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');

  • 第2步:

打开您的WordPress主题的style.css文件,并将下面的代码放入更好的样式。

代码语言:javascript
复制
    .crunchify-link {
    padding: 4px 8px 6px 8px;
    color: white;
    font-size: 12px;
    border-radius: 2px;
    margin-right: 2px;
    cursor: pointer;
    -moz-background-clip: padding;
    -webkit-background-clip: padding-box;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
    -moz-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
    -webkit-box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}

.crunchify-link:hover,.crunchify-link:active {
    color: white;
}

.crunchify-twitter {
    background: #00aced;
}

.crunchify-twitter:hover,.crunchify-twitter:active {
    background: #0084b4;
}

.crunchify-facebook {
    background: #3B5997;
}

.crunchify-facebook:hover,.crunchify-facebook:active {
    background: #2d4372;
}

.crunchify-googleplus {
    background: #D64937;
}

.crunchify-googleplus:hover,.crunchify-googleplus:active {
    background: #b53525;
}

.crunchify-buffer {
    background: #444;
}

.crunchify-buffer:hover,.crunchify-buffer:active {
    background: #222;
}

.crunchify-pinterest {
    background: #bd081c;
}

.crunchify-pinterest:hover,.crunchify-pinterest:active {
    background: #bd081c;
}
.crunchify-social {
    margin: 20px 0px 25px 0px;
    -webkit-font-smoothing: antialiased;
    font-size: 12px;
}

  • 如果您想在帖子顶部显示共享按钮,请使用以下代码:

代码语言:javascript
复制
function crunchify_social_sharing_buttons($content) {
    if(is_singular() || is_home()){

        // Get current page URL 
        $crunchifyURL = get_permalink();

        // Get current page title
        $crunchifyTitle = str_replace( ' ', '%20', get_the_title());

        // Get Post Thumbnail for pinterest
        $crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );

        // Construct sharing URL without using any script
        $twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&amp;url='.$crunchifyURL.'&amp;via=Crunchify';
        $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
        $googleURL = 'https://plus.google.com/share?url='.$crunchifyURL;
        $bufferURL = 'https://bufferapp.com/add?url='.$crunchifyURL.'&amp;text='.$crunchifyTitle;

        // Based on popular demand added Pinterest too
        $pinterestURL = 'https://pinterest.com/pin/create/button/?url='.$crunchifyURL.'&amp;media='.$crunchifyThumbnail[0].'&amp;description='.$crunchifyTitle;

        // Add sharing button at the end of page/page content
        $variable .= '<div class="crunchify-social">';
        $variable .= '<a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
        $variable .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
        $variable .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
        $variable .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
        $variable .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" target="_blank">Pin It</a>';
        $variable .= '</div>';

        return $variable.$content;
    }else{
        // if not a post/page then don't include sharing button
        return $variable.$content;
    }
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');

看一看here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33448275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档