Xwriteで「人気記事ランキング」ウィジェットを好きな場所に表示するカスタマイズ

カスタマイズ
この記事は約8分で読めます。
記事内に広告が含まれています。

Xwrite 4.0.7

はじめに

Xwriteで、以下を実現します。

Xwriteの「人気記事ランキング」ウィジェットは、ウィジェットエリアにしか設置できません。
そのため、記事本文や固定ページなど、好きな場所に表示したい場合は不便に感じることがあります。

以前の記事では、WordPressのウィジェットをショートコードで呼び出す方法を紹介しました。

この方法をXwriteの人気記事ランキングにも応用すれば、ウィジェットエリアに限らず、投稿本文や固定ページなどにも自由に配置できます。

この記事では、この方法について説明します。

完成イメージ

使用方法

以下にショートコードを示します。

[my_widget name="XW_Ranking_Posts_Widget" options='{"thumb_ratio":"--posts--thumb--ratio--card:61.8%; --posts--thumb--ratio--list:61.8%;"}']

options にJSON形式で値を渡すと、サムネイルの縦横比を変更できます(表1参照)。

ショートコードの options に指定するJSONは、改行せずに入力してください。

{
  "thumb_ratio": "--posts--thumb--ratio--card:61.8%; --posts--thumb--ratio--list:61.8%;"
}
options
画像の比率オプション値
黄金比(1:1.618)–posts–thumb–ratio–card:61.8%; –posts–thumb–ratio–list:61.8%;
スタンダード(4:3)–posts–thumb–ratio–card:75%; –posts–thumb–ratio–list:75%;
ワイド(16:9)–posts–thumb–ratio–card:56.25%; –posts–thumb–ratio–list:56.25%;
OGP比(1:1.91)–posts–thumb–ratio–card:52.5%; –posts–thumb–ratio–list:52.5%;
正方形(1:1)–posts–thumb–ratio–card:100%; –posts–thumb–ratio–list:100%;

参考:他ウィジェットをショートコードで使用する場合

ウィジェット

Xwriteには、SNS、プロフィール、人気記事ランキングの3種類のウィジェットが用意されています(図1参照)。

前述で説明した人気記事ランキングに加え、SNSとプロフィールについても、ショートコードで表示・設定する方法を紹介します。

「SNS」ウィジェットの表示

ショートコードの name は XW_Sns_Widget とし、options はJSON形式で値を渡します(表2参照)。

{
  "title": "SNS",
  "twitter": "https://x.com/アカウント名",
  "facebook": "https://www.facebook.com/アカウント名",
  "instagram": "https://www.instagram.com/アカウント名",
  "youtube": "https://www.youtube.com/@チャンネル名"
}
options
オプション説明
twitterX(旧Twitter)のURL
facebookFacebookのURL
instagramInstagramのURL
youtubeYouTubeのURL

「プロフィール」ウィジェットの表示

ショートコードの name は XW_Profile_Widget とし、options はJSON形式で値を渡します(表3参照)。

{
  "name": "サイト管理者",
  "description": "サイトの紹介文です。",
  "show_avatar": "true",
  "avatar": "https://example.com/profile.png",
  "show_background": "true",
  "background": "https://example.com/background.png",
  "twitter": "https://x.com/アカウント名",
  "facebook": "https://www.facebook.com/アカウント名",
  "instagram": "https://www.instagram.com/アカウント名",
  "youtube": "https://www.youtube.com/@チャンネル名"
}
options
オプション説明
titleウィジェットのタイトル
nameプロフィール名
descriptionプロフィールの紹介文
show_avatarアバター画像の表示("true"で表示)
avatarアバター画像のURL
show_background背景画像の表示("true"で表示)
background背景画像のURL
twitterX(旧Twitter)のURL
facebookFacebookのURL
instagramInstagramのURL
youtubeYouTubeのURL
タイトルとURLをコピーしました