jQueryで実現するライトボックス効果とともに、ページにギャラリーを設定しようとしています。
jQuery がこのクラスをターゲットにしてその処理を実行できるように、各画像にクラスを追加する必要があります。残念ながら、特定のカテゴリ内の画像にのみこの効果を適用する必要があるため、jQuery を使用してクラスを追加することはできません。
これまでの私のコードは次のとおりです(動作しません):
if ( in_category( 'gallery' )) {
/** * Attach a class to linked images' parent anchors * e.g. a img => a.img img */
function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '' ){ $classes = 'gallery_img gllry'; // separated by spaces, e.g. 'img image-link'
// check if there are already classes assigned to the anchor
if ( preg_match('/<a.*? class=".*?">/', $html) ) { $html = preg_replace('/(<a.*? class=".*?)(".*?>)/', '$1 ' . $classes . '$2', $html); } else { $html = preg_replace('/(<a.*?)>/', '$1 class="' . $classes . '" >', $html); } return $html; } add_filter('image_send_to_editor','give_linked_images_class',10,8);
私はそれを自分のテーマの functions.php と nada, zilch に入れました。カテゴリ「ギャラリー」内のタグ内のimgタグをターゲットにする必要がありますか?
どんな助けでも本当に感謝しています。