0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

wordpressでのタグ表示数をphpで設定する方法

Last updated at Posted at 2023-03-10

wordpressのタグ表示数はphpで制御できる。

ワードプレスに備わっているタグクラウド。
そんなタグクラウドにおけるタグ表示数はphpで制御できます。
たとえば下図はタグ表示数を45→20へ変更した例です。
タグ数.png
こんな感じでタグ表示数により見栄えが変わります。

phpの記述方法

php更新によりウェブサイトが上手く機能しないリスクもあります。phpの記述は自己責任でお願いします。
wordpressにおけるphp更新は、外観→テーマエディター→Function.phpより記述を追加できます。
以下にサンプルコードを例示します。Function.phpの最後あたりにコピペすると使えます。

php
function custom_wp_tag_cloud($args) {
$myargs = array(
‘orderby’ => ‘count’, //使用頻度を取得する
‘order’ => ‘DESC’, // 降順(使用頻度の高い順)
‘number’ => 45 // 表示数
);
$args = wp_parse_args($args, $myargs);
return $args;
}
add_filter( ‘widget_tag_cloud_args’, ‘custom_wp_tag_cloud’ );

(phpの記述方法は https://tensyokuseikatsu.com/wordpress-tag-count/ を参照)

php構文解説

//でコメントアウトしている部分を参考に、変数を変更することで表示数を変えることが出来ます。
たとえばnumberの45を、20へと変更すると表示タグ数を変更することが出来ます。
見栄えの良いウェブサイトへの更新へ役立つことが出来れば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?