【JSなし】この記事が気に入ったらいいね!ではなくシェアのリンクを設置する方法

【JSなし】この記事が気に入ったらいいね!ではなくシェアのリンクを設置する方法

カスタマイズ SNS
2018/07/05
2
vanillaice (Akira)
vanillaice (Akira)
InstructionHTMLCSSFacebook初心者向け

巷でよく見かける「この記事が気に入ったらいいね!」なんで「いいね(Like!)」なんですかね (´・ω・`)
アクセス増やしたいならいいねよりシェアだと思うのだけれど。

今回は目立つシェアリンクを設置しよう、という主旨でございます。いいねじゃなくシェアね。シェア。

「いいね」だとJSが要りますし、いいねにしてもシェアにしても数を表示させようと思うとこれまたJSが要ります。今回はそういうのはなしで単純なシェアリンクで。数が出てると「少ないとなんか恥ずかしいな…」とか変な方向に行ったり自分で押しちゃったりする人が出てきて精神衛生上良くないので数も無し(笑)
htmlとCSSのみ、コピペでの簡単実装です。

・Font AwesomeのJS(svg)が導入されていることを前提としています。FC2ブログでの利用を前提としています。

全パターン共通html

<div id="fb-btn-wrapper">
  <div id="fb-thumb">
    <img id="fb-share-image" src="<%topentry_image_url>" width="横実寸" height="縦実寸" alt="">
  </div>
  <div id="fb-text">
    <p id="share-p">この記事が気に入ったら<br>シェア!</p>
    <a id="fb-share-btn" href="https://www.facebook.com/sharer.php?u=<%topentry_link>&amp;t=<%topentry_enc_title>" target="_blank" title="Share on Facebook"><i class="fab fa-facebook-square"></i>シェア</a>
  </div>
</div>

テンプレート内に <!--/more--> というのが1箇所ありますので、その直下に記載してください。

パターン別CSS

スマートフォンでの見え方は実機を利用するかブラウザを縮小するなどして確認してください。
ブレイクポイントは適当なので各自調整してください。
(デフォルトでは画面横幅520以下でレイアウトが切り替わります)
スマートフォンから閲覧中の方は全て同じ見た目になっていますので、ランドスケープ(横倒し)でご覧ください。

この記事が気に入ったら
シェア!

シェア
#fb-btn-wrapper {
  display: flex;
  height: 250px;/* 全体の高さ */
  line-height: 1.6em;
}

#fb-thumb {
  flex: 1;
  height: 100%;
}

#fb-share-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

#fb-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 250px;/* 右側横幅 */
  height: 100%;
  background-color: rgb(51,51,51);/* 右側背景色 */
  color: white;
  text-align: center;
}

#share-p {
  margin: 1.9em 0;
  font-size: 16px;/* テキスト大きさ */
}

#fb-share-btn {
  display: inline-flex;
  align-items: center;
  padding: .2em .8em;
  border-radius: 2px;
  background-color: rgb(59,89,152);
  color: white;
  font-size: 12px;
}

#fb-share-btn:hover {
  text-decoration: none !important;
}

#fb-share-btn .svg-inline--fa {
  margin-right: .6em;
}

/* break point */
@media screen and (max-width: 520px) {
  #fb-btn-wrapper {
    display: block;
    position: relative;
    height: 180px;/* 全体高さ */
  }
  #fb-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background-color: rgba(51,51,51,.7);
  }
}

この記事が気に入ったら
シェア!

シェア
#fb-btn-wrapper {
  display: flex;
  flex: 1;
  height: 250px;
  line-height: 1.6em;
}

#fb-thumb {
  width: 50%;
  height: 100%;
}

#fb-share-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

#fb-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 50%;
  height: 100%;
  background-color: rgb(51,51,51);/* 右側背景色 */
  color: white;
  text-align: center;
}

#share-p {
  margin: 1.9em 0;
  font-size: 16px;/* テキスト大きさ */
}

#fb-share-btn {
  display: inline-flex;
  align-items: center;
  padding: .2em .8em;
  border-radius: 2px;
  background-color: rgb(59,89,152);
  color: white;
  font-size: 12px;
}

#fb-share-btn:hover {
  text-decoration: none !important;
}

#fb-share-btn .svg-inline--fa {
  margin-right: .6em;
}

/* break point */
@media screen and (max-width: 520px) {
  #fb-btn-wrapper {
    display: block;
    position: relative;
    height: 180px;/* 全体高さ */
  }
  fb-thumb2 {
    width: 100%;
  }
  #fb-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(51,51,51,.7);
  }
}

この記事が気に入ったら
シェア!

シェア
#fb-btn-wrapper {
  position: relative;
  height: 250px;
  line-height: 1.6em;
}

#fb-share-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

#fb-thumb {
  height: 100%;
}

#fb-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  right: 0;
  width: 250px;/* オーバーレイを全体の半分にするには 50% に変更 */
  height: 100%;
  background-color: rgba(51,51,51,.7);/* 右側背景色 */
  color: white;
  text-align: center;
}

#share-p {
  margin: 1.9em 0;
  font-size: 16px;/* テキスト大きさ */
}

#fb-share-btn {
  display: inline-flex;
  align-items: center;
  padding: .2em .8em;
  border-radius: 2px;
  background-color: rgb(59,89,152);
  color: white;
  font-size: 12px;
}

#fb-share-btn:hover {
  text-decoration: none !important;
}

#fb-share-btn .svg-inline--fa {
  margin-right: .6em;
}

/* break point */
@media screen and (max-width: 520px) {
  #fb-btn-wrapper {
    height: 180px;/* 全体高さ */
  }
  #fb-text {
    width: 100%;
  }
}

この記事が気に入ったら
シェア!

シェア
#fb-btn-wrapper {
  position: relative;
  height: 250px;
  line-height: 1.6em;
}

#fb-share-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
}

#fb-thumb {
  height: 100%;
}

#fb-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(51,51,51,.7);/* 右側背景色 */
  color: white;
  text-align: center;
}

#share-p {
  margin: 1.9em 0;
  font-size: 16px;/* テキスト大きさ */
}

#fb-share-btn {
  display: inline-flex;
  align-items: center;
  padding: .2em .8em;
  border-radius: 2px;
  background-color: rgb(59,89,152);
  color: white;
  font-size: 12px;
}

#fb-share-btn:hover {
  text-decoration: none !important;
}

#fb-share-btn .svg-inline--fa {
  margin-right: .6em;
}

/* break point */
@media screen and (max-width: 520px) {
  #fb-btn-wrapper {
    height: 180px;/* 全体高さ */
  }
}

まとめ

デザインカスタマイズはご自由に。htmlとCSSだけなので比較的容易かと思います。テンプレートデザインで個別記事にヒーローヘッダーが付いているものなどはちょっとしつこいかなぁと思いますが、そこは個人の裁量で。

Facebookの連携投稿が終了するのにFC2運営から何のアナウンスもありませんね。クレーム回避のためにもなるべく早くお知らせを(笑)

Related post

Comments  2

ロビンソン
2018/07/09 (Mon) 20:04

お世話になります。
記事を読んで導入させていただきました。
カスタマイズの際にhtml内の<img id="fb-share-image" src="<%topentry_image_url>">の部分にalt=""を書き加えましたが、よかったでしょうか?

vanillaice (Akira)
Akira
2018/07/10 (Tue) 12:28

To ロビンソンさん

ロビンソンさん、こんにちは ('0')/

はい。altも入れてください。
そしてもちろんロビンソンさんはlazyloading導入済みなのでそれ用の記述で書いてくださいね。
ソースにalt抜けてましたね。追加しておきました。ありがとうございます :)

コメントに関する注意事項
  • テンプレートに関するご質問は各テンプレート専用記事でのみ受付致します。また、よくある質問をまとめているページも事前にご参照ください。
  • 専門的なご質問の場合、記事内容と明らかに関連の無い内容はお控えください(雑談の場合はその限りではありません)
  • 第三者が不快と感じる内容や論調でのコメントはお控えください(性的,高圧的,暴力的など)