賢威にてページのSNSソーシャルボタンを見やすくし、スマホにもサイズ対応させました。
すべて子テーマにて行っています。
編集しても問題が起こりにくい順に記載していきます。
SNS Count Cacheのプラグイン導入
プラグイン→新規追加で
SNS Count Cache
をインストールして有効
Webアイコンフォント「Font Awesome」を実装
このあたりが少し手間かもしれませんがやってしまえば後が楽です。
やることはファイルをダウンロード→ファイルマネージャーでwww/のルート下に「Font」フォルダを作る→「Font Awesome」や「IcoMoon」でダウンロードしたファイルをアップロードです。
参考
賢威7でWebアイコンフォント「Font Awesome」を実装する方法
https://ruzyu.com/7155
IcoMoonではてな、LINE、feedlyのアイコンを手に入れる
はてな、LINE、feedlyのアイコンはないのでIcoMoonでダウンロードしてルートに置く
賢威7で「はてなブックマーク」「LINE」「feedly」のWebアイコンフォントを実装する方法
https://ruzyu.com/7207
賢威の設定から「Font Awesome」「IcoMoon」のスタイルを読み込ませるコード記載
賢威の設定→賢威の設定→下の辺りの項目の直前に挿入するコード記入欄に
※参考サイトではcssへとなっていたのですが、
「Font Awesome」のccsファイルは「fontawesome.min.css」(ハイフンなし)なので、
に変えました。
base.cssに追記
CSSファイルに追記していきます。
「base.css」に以下を追記。
「base.css」はPC用スタイルシートです。(賢威7対応)
「base.css」に追記するスタイルシート
/*-------------------------------------------------------- SNSボタン --------------------------------------------------------*/ .share{ width:100%; } .sns{ margin:0 auto; text-align:center; } .sns ul { list-style:none; } .sns li { float:left; width:48%; margin:0 2% 3% 0; } .sns li a { font-size:80%; position:relative; display:block; padding:10px; color:#fff; border-radius:6px; text-align:center; text-decoration: none; text-shadow:1px 1px 0 rgba(255,255,255,0.3); } .sns li a:hover { -webkit-transform: translate3d(0px, 5px, 1px); -moz-transform: translate3d(0px, 5px, 1px); transform: translate3d(0px, 5px, 1px); box-shadow:none; } /* ツイッター */ .sns .twitter a { background:#00acee; box-shadow:0 5px 0 #0092ca; } .sns .twitter a:hover { background:#0092ca; } /* Facebook */ .sns .facebook a { background:#3b5998; box-shadow:0 5px 0 #2c4373; } .sns .facebook a:hover { background:#2c4373; } /* グーグル */ .sns .googleplus a { background:#db4a39; box-shadow:0 5px 0 #ad3a2d; } .sns .googleplus a:hover { background:#ad3a2d; } /* はてぶ */ .sns .hatebu a { background:#5d8ac1; box-shadow:0 5px 0 #43638b; } .sns .hatebu a:hover { background:#43638b; } /* LINE */ .sns .line a { background:#25af00; box-shadow:0 5px 0 #219900; } .sns .line a:hover { background:#219900; } /* Pocket */ .sns .pocket a { background:#f03e51; box-shadow:0 5px 0 #c0392b; } .sns .pocket a:hover { background:#c0392b; } /* RSS */ .sns .rss a { background:#ffb53c; box-shadow:0 5px 0 #e09900; } .sns .rss a:hover { background:#e09900; } /* Feedly */ .sns .feedly a { background:#87c040; box-shadow:0 5px 0 #74a436; } .sns .feedly a:hover { background:#74a436; } /*-------------------------------------- 780px SNS --------------------------------------*/ .share{ padding-bottom:10px; } .sns ul { margin:0 auto; list-style:none; } .sns li { width:23%; margin:0 2% 3% 0; } .sns li a { font-size:75%; padding:10px 2px; } .sns li:nth-child(4n) { margin-right:0; }
rwd.cssに追記
「rwd.css」に追記するスタイルシート
「rwd.css」はスマホ用スタイルシートです。
/*-------------------------------------------------------- 解像度1200px以下 --------------------------------------------------------*/ @media only screen and (max-width : 1200px){ /*-------------------------------- SNS ---------------------------------*/ .share{ width:100%; } .sns{ margin:0 auto; text-align:center; } .sns ul { list-style:none; } .sns li { float:left; width:48%; margin:0 2% 3% 0; } .sns li a { font-size:80%; position:relative; display:block; padding:10px; color:#fff; border-radius:6px; text-align:center; text-decoration: none; text-shadow:1px 1px 0 rgba(255,255,255,0.3); } .sns li a:hover { -webkit-transform: translate3d(0px, 5px, 1px); -moz-transform: translate3d(0px, 5px, 1px); transform: translate3d(0px, 5px, 1px); box-shadow:none; } /* ツイッター */ .sns .twitter a { background:#00acee; box-shadow:0 5px 0 #0092ca; } .sns .twitter a:hover { background:#0092ca; } /* Facebook */ .sns .facebook a { background:#3b5998; box-shadow:0 5px 0 #2c4373; } .sns .facebook a:hover { background:#2c4373; } /* グーグル */ .sns .googleplus a { background:#db4a39; box-shadow:0 5px 0 #ad3a2d; } .sns .googleplus a:hover { background:#ad3a2d; } /* はてぶ */ .sns .hatebu a { background:#5d8ac1; box-shadow:0 5px 0 #43638b; } .sns .hatebu a:hover { background:#43638b; } /* LINE */ .sns .line a { background:#25af00; box-shadow:0 5px 0 #219900; } .sns .line a:hover { background:#219900; } /* Pocket */ .sns .pocket a { background:#f03e51; box-shadow:0 5px 0 #c0392b; } .sns .pocket a:hover { background:#c0392b; } /* RSS */ .sns .rss a { background:#ffb53c; box-shadow:0 5px 0 #e09900; } .sns .rss a:hover { background:#e09900; } /* Feedly */ .sns .feedly a { background:#87c040; box-shadow:0 5px 0 #74a436; } .sns .feedly a:hover { background:#74a436; } }
sns_button.phpの書き換え
「sns_button.php」に記載するコード
元よりあった
<aside class="sns-list"> <ul> <li class="sb-tweet"> <a href="https://twitter.com/share" data-text="<?php the_title(); ?> | <?php bloginfo('name'); ?>" data-url="<?php the_permalink(); ?>" class="twitter-share-button" data-lang="ja"><?php _e('Tweet', 'keni'); ?></a> </li> <li class="sb-hatebu"> <a href="http://b.hatena.ne.jp/entry/<?php the_permalink(); ?>" data-hatena-bookmark-title="<?php the_title(); ?> | <?php bloginfo('name'); ?>" class="hatena-bookmark-button" data-hatena-bookmark-layout="simple-balloon" title="<?php _e('Add this entry to Hatena Bookmark.', 'keni'); ?>"><img src="https://b.st-hatena.com/images/entry-button/button-only@2x.png" alt="<?php _e('Add this entry to Hatena Bookmark.', 'keni'); ?>" width="20" height="20" style="border: none;" /></a> </li> <li class="sb-fb-like"> <div class="fb-like" data-width="110" data-href="<?php the_permalink(); ?>" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div> </li> <li class="sb-gplus"> <div class="g-plusone" data-href="<?php the_permalink(); ?>" data-size="medium"></div></li> </ul> </aside>
・・を全消しして、(要バックアップです!!)
<?php $url_encode=urlencode(get_permalink()); $title_encode=urlencode(get_the_title()); ?> <div class="share"> <?php if(is_mobile()) { //以下スマホの場合 ?> <div class="sns"> <ul class="clearfix"> <!--ツイートボタン--> <li class="twitter"><a href="http://twitter.com/share?text=<?php echo $title_encode ?>&url=<?php echo $url_encode ?>&via=tokeyneale&tw_p=tweetbutton&related="tokeyneale"><i class="fa fa-twitter"></i>Twitter<?php if(function_exists('scc_get_share_twitter')) echo (scc_get_share_twitter()==0)?'':scc_get_share_twitter(); ?></a></li> <!--Facebookボタン--> <li class="facebook"><a href="http://www.facebook.com/sharer.php?src=bm&u=<?php echo $url_encode;?>&t=<?php echo $title_encode;?>"><i class="fa fa-facebook"></i>Facebook<?php if(function_exists('scc_get_share_facebook')) echo (scc_get_share_facebook()==0)?'':scc_get_share_facebook(); ?></a></li> <!--Google+1ボタン--> <li class="googleplus"><a href="https://plus.google.com/share?url=<?php echo $url_encode;?>" ><i class="fa fa-google-plus"></i>Google+<?php if(function_exists('scc_get_share_gplus')) echo (scc_get_share_gplus()==0)?'':scc_get_share_gplus(); ?></a></li> <!--はてブボタン--> <li class="hatebu"><a href="http://b.hatena.ne.jp/add?mode=confirm&url=<?php echo $url_encode ?>"><i class="icon-hatebu"></i>B!<?php if(function_exists('scc_get_share_hatebu')) echo (scc_get_share_hatebu()==0)?'':scc_get_share_hatebu(); ?></a></li> <!--ポケットボタン--> <li class="pocket"><a href="http://getpocket.com/edit?url=<?php echo $url_encode;?>&title=<?php echo $title_encode;?>"><i class="fa fa-get-pocket"></i>pocket<?php if(function_exists('scc_get_share_pocket')) echo (scc_get_share_pocket()==0)?'':scc_get_share_pocket(); ?></a></li> <!--feedlyボタン--> <li class="feedly"><a href="http://feedly.com/index.html#subscription%2Ffeed%2Fhttp%3A%2F%2F★★あなたのサイトのドメイン(例)libpsy.com★★%2Ffeed%2F" target="blank"><i class="icon-feedly"></i>feedly<?php if(function_exists('scc_get_follow_feedly')) echo (scc_get_follow_feedly()==0)?'':scc_get_follow_feedly(); ?></a></li> <!--LINEボタン--> <li class="line"><a href="http://line.me/R/msg/text/?<?php echo $title_encode . '%0A' . $url_encode;?>"><i class="icon-line"></i>LINE</a></li> </ul> </div> <?php } else { //以下PCの場合?> <div class="sns"> <ul class="clearfix"> <!--ツイートボタン--> <li class="twitter"> <a href="http://twitter.com/intent/tweet?url=<?php echo $url_encode; ?>&text=<?php echo $title_encode . urlencode( ' | ' ); echo urlencode( get_bloginfo('name')); ?>&via=<?php echo $twitter_account; ?>&tw_p=tweetbutton&related="<?php echo $twitter_account; ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><i class="fa fa-twitter"></i><span class="pc">Twitter</span></a> </li> <!--Facebookボタン--> <li class="facebook"> <a href="http://www.facebook.com/sharer.php?src=bm&u=<?php echo $url_encode;?>&t=<?php echo $title_encode;?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><i class="fa fa-facebook"></i><span class="pc">Facebook</span><span class="share-count"><?php if(function_exists('get_scc_facebook')) { echo scc_get_share_facebook();}?></span></a> </li> <!--Google+1ボタン--> <li class="googleplus"> <a href="https://plus.google.com/share?url=<?php echo $url_encode;?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><i class="fa fa-google-plus"></i><span class="pc">Google+</span><span class="share-count"><?php if(function_exists('get_scc_gplus')) { echo scc_get_share_gplus();}?></span></a> </li> <!--はてブボタン--> <li class="hatebu"> <a href="http://b.hatena.ne.jp/add?mode=confirm&url=<?php echo $url_encode ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><span class="hatena-icon">B!</span><span class="pc"></span><span class="share-count"><?php if(function_exists('get_scc_hatebu')) { echo scc_get_share_hatebu();}?></span></a> </li> <!--ポケットボタン--> <li class="pocket"> <a class="no-deco" target="_blank" href="http://getpocket.com/edit?url=<?php echo $url_encode; ?>&title=<?php echo $title_encode; ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><i class="fa fa-get-pocket"></i><span class="pc">Pocket</span><span class="share-count"><?php if(function_exists('scc_get_share_pocket')) echo scc_get_share_pocket(); ?></span></a> </li> <!--feedlyボタン--> <li class="feedly"> <a href="http://feedly.com/i/subscription/feed/<?php bloginfo('rss2_url'); ?>" rel="nofollow" target="_blank"><i class="fa fa-rss"></i>feedly <?php if(function_exists('scc_get_follow_feedly')) echo (scc_get_follow_feedly()==0)?'':scc_get_follow_feedly(); ?></a> </li> </ul> </div> <?php } ?> </div>
functions.phpに追記
「functions.php」に以下を追記。
//スマホ表示分岐
function is_mobile(){
$useragents = array(
‘iPhone’, // iPhone
‘iPod’, // iPod touch
‘Android.*Mobile’, // 1.5+ Android *** Only mobile
‘Windows.*Phone’, // *** Windows Phone
‘dream’, // Pre 1.5 Android
‘CUPCAKE’, // 1.5+ Android
‘blackberry9500’, // Storm
‘blackberry9530’, // Storm
‘blackberry9520’, // Storm v2
‘blackberry9550’, // Storm v2
‘blackberry9800’, // Torch
‘webOS’, // Palm Pre Experimental
‘incognito’, // Other iPhone browser
‘webmate’ // Other iPhone browser);
$pattern = ‘/’.implode(‘|’, $useragents).’/i’;
return preg_match($pattern, $_SERVER[‘HTTP_USER_AGENT’]);
}