1
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 5 years have passed since last update.

【WordPress】post_classに好きなclassを追加する方法(WP初心者メモ)

Posted at

WordPressでpost_classを使って好きなclassを追加する方法のメモ。
自動でクラスを追加してくれるpost_class();ですが、ここにクラスを追加したい場合は()の中に記入します。

<?php post_class('ここにクラス名'); ?>

()の中にクラスを追加する時は''を忘れないように・・・!

例えば、hogeというクラスを追加する場合は

<?php post_class('hoge') ?>

と書けばOK。

複数のクラスを追加する場合

スペースで追加する方法

複数のクラスを追加したい場合はスペース空けて記入していきます。

<?php post_class('hoge fuga') ?>

配列で追加する方法

<?php
	$classes = array( 'class1', 'class2', 'class3' );
?>
<div id="post-<?php the_ID(); ?>" <?php post_class( $classes ); ?>>

複数のクラスのセットを使いまわしたい場合は配列にして使用するのが便利かもしれないですね。

Codex テンプレートタグ/post class

1
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
1
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?