社會化分享功能幾乎國外主題,説白點就是模板中都會加入社會化功能。但是我朝內用户使用國外模板時候,社會化分享幾乎成了擺設,原因你懂的。所以,一般都會把分享功能改成適合我朝國情的社會化分享。
下面是各網站的 API 接口及 URL:
新浪微博開放平台:http://open.weibo.com/
騰訊微博開放平台:http://open.t.qq.com/index.php
QQ(騰訊社區) 開放平台: http://opensns.qq.com/
人人網:http://dev.renren.com/
開心網:http://www.kaixin001.com/platform/
豆瓣:http://www.douban.com/service/
MSN:http://www.windowslive.cn/mc/、 所有功能需要自己開發應用 http://msdn.microsoft.com/en-us/windowslive/default.aspx
MSN 連接成功案例展示:http://connectdemos.com/
下面以 WordPress The7 主題為例。其實最方面的還是直接通過 JiaThis API 接口分享 (http://www.jiathis.com/help/html/share-with-jiathis-api) 百度的也是可以有的!
JiaThis API 接口 使用如下 (http://www.jiathis.com/help/html/share-with-jiathis-api):
http://www.jiathis.com/send/?webid=shareID&url=$siteUrl&title=$siteTitle&uid=$uid
shareID 分享 ID 參數代表你要分享到哪個站點的 ID 編號, 可以通過這個文檔查詢:分享網站 ID 清單
$siteUrl 參數代表你要分享的網站鏈接地址,可以通過動態程序調用
$siteTitle 參數代表你要分享的網站頁面標題,可以通過動態程序調用,也可自定義。
$uid(非必須) 代表你註冊 JiaThis 的會員 UID,可以登錄網站後查到您的 UID,用於數據統計。
舉例 1:分享到開心網代碼
舉例 2:分享到人人網代碼
舉例 3:分享到新浪微博代碼
舉例 4:分享到 QQ 空間代碼
這樣的格式比起直接調用各個網站的接口來,使用更方便,代碼維護更簡單。
總的來説,http://www.jiathis.com/send/?webid=shareID&url=$siteUrl&title=$siteTitle&uid=$uid 這段分享 API 接口中和昨天那篇多説分享的差
不多的,無非就傳遞幾個參數問題。
在 The7 v4.4.5 中 functions.php 中分享的 social icons 在函數 presscore_get_social_icons_data() 中,直接 return 回去。
function presscore_get_social_icons_data() { return array( 'facebook' => __('Facebook', LANGUAGE_ZONE), 'twitter' => __('Twitter', LANGUAGE_ZONE), 'google' => __('Google+', LANGUAGE_ZONE), 'dribbble' => __('Dribbble', LANGUAGE_ZONE), 'you-tube' => __('YouTube', LANGUAGE_ZONE), 'rss' => __('Rss', LANGUAGE_ZONE), 'delicious' => __('Delicious', LANGUAGE_ZONE), 'flickr' => __('Flickr', LANGUAGE_ZONE), 'forrst' => __('Forrst', LANGUAGE_ZONE), 'lastfm' => __('Lastfm', LANGUAGE_ZONE), 'linkedin' => __('Linkedin', LANGUAGE_ZONE), 'vimeo' => __('Vimeo', LANGUAGE_ZONE), 'tumbler' => __('Tumblr', LANGUAGE_ZONE), 'pinterest' => __('Pinterest', LANGUAGE_ZONE), 'devian' => __('Deviantart', LANGUAGE_ZONE), 'skype' => __('Skype', LANGUAGE_ZONE), 'github' => __('Github', LANGUAGE_ZONE), 'instagram' => __('Instagram', LANGUAGE_ZONE), 'stumbleupon' => __('Stumbleupon', LANGUAGE_ZONE), 'behance' => __('Behance', LANGUAGE_ZONE), 'mail' => __('Mail', LANGUAGE_ZONE), 'website' => __('Website', LANGUAGE_ZONE), 'px-500' => __('500px', LANGUAGE_ZONE), 'tripedvisor' => __('TripAdvisor', LANGUAGE_ZONE), 'vk' => __('VK', LANGUAGE_ZONE), 'foursquare' => __('Foursquare', LANGUAGE_ZONE), 'xing' => __('XING', LANGUAGE_ZONE), 'weibo' => __('Weibo', LANGUAGE_ZONE), );
}
找到這個函數,把國外不和諧的改成我朝內的即可
分享網站的清單,自己去找!需要什麼就替換什麼!
第二步:找到 helpers.php
foreach ( $buttons as $button ) { $classes = array( 'share-button' ); $url = ''; $desc = $buttons_list[ $button ]; $share_title = _x('share', 'share buttons', LANGUAGE_ZONE); $custom = ''; switch( $button ) { case 'twitter': $classes[] = 'twitter'; $share_title = _x('tweet', 'share buttons', LANGUAGE_ZONE); $url = add_query_arg( array('status' => urlencode($t . ' ' . $u) ), $protocol . '://twitter.com/home' ); break; case 'facebook': $url_args = array( 's=100', urlencode('p[url]') . '=' . esc_url($u), urlencode('p[title]') . '=' . urlencode($t) ); if ( has_post_thumbnail( $options['id'] ) ) { $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $options['id'] ), 'full' ); if ( $thumbnail ) { $url_args[] = urlencode('p[images][0]') . '=' . esc_url($thumbnail[0]); } } // mobile args $url_args[] = 't=' . urlencode($t); $url_args[] = 'u=' . esc_url($u); $classes[] = 'facebook'; $url = $protocol . '://www.facebook.com/sharer.php?' . implode( '&', $url_args ); break; case 'google+': $t = str_replace(' ', '+', $t); $classes[] = 'google'; $url = add_query_arg( array('url' => $u, 'title' => $t), $protocol . '://plus.google.com/share' ); break; case 'pinterest': $url = '//pinterest.com/pin/create/button/'; $custom = ' data-pin-config="above" data-pin-do="buttonBookmark"'; // if image if ( wp_attachment_is_image($options['id']) ) { $image = wp_get_attachment_image_src($options['id'], 'full'); if ( !empty($image) ) { $url = add_query_arg( array( 'url' => $u, 'media' => $image[0], 'description' => $t ), $url ); $custom = ''; } } $classes[] = 'pinterest'; $share_title = _x('pin it', 'share buttons', LANGUAGE_ZONE); break; } $desc = esc_attr($desc); $share_title = esc_attr($share_title); $classes_str = esc_attr( implode(' ', $classes) ); $url = esc_url( $url ); $share_button = sprintf( '<a href="%2$s" target="_blank" title="%3$s"%5$s><span >%3$s</span><span >%4$s</span></a>', $classes_str, $url, $desc, $share_title, $custom ); $html .= apply_filters( 'presscore_share_button', $share_button, $button, $classes, $url, $desc, $share_title, $t, $u ); } $html .= '</div> </div>'; $html = apply_filters( 'presscore_display_share_buttons', $html ); if ( $options['echo'] ) { echo $html; } return $html;
} endif; // presscore_display_share_buttons
別看一大段,其實都是尼瑪的 case 語句
case 'twitter': $classes[] = 'twitter';
$share_title = _x('tweet', 'share buttons', LANGUAGE_ZONE);
$url = add_query_arg( array('status' => urlencode($t . ' ' . $u) ), $protocol . '://twitter.com/home' );
break;
替換成我朝的渣浪
case 'tsina': $t = str_replace(' ', '+', $t); //去除空格
$classes[] = 'tsina';
$share_title = _x('新浪微博', 'share buttons', LANGUAGE_ZONE);
$url = add_query_arg( array('url' => $u, 'title' => $t), $protocol . '://www.jiathis.com/send/?webid=tsina&' );
break;
其它的以此類推。
搞完就完事了。直接使用,不用加載一堆 js