Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 检查是否在特定类别中,然后添加一个类以在Wordpress中发布图像_Image_Wordpress_Class_Post - Fatal编程技术网

Image 检查是否在特定类别中,然后添加一个类以在Wordpress中发布图像

Image 检查是否在特定类别中,然后添加一个类以在Wordpress中发布图像,image,wordpress,class,post,Image,Wordpress,Class,Post,我正在尝试在页面上设置一个图库,以及一个lightbox效果,我将使用jQuery实现这个效果 我需要为每个图像添加一个类,这样jQuery就可以针对这个类并完成它的工作-不幸的是,我还需要这种效果来只应用于给定类别中的图像-所以用jQuery添加类是行不通的 以下是我到目前为止的代码(它不起作用): if(在_类('gallery')){ /***将类附加到链接图像的父锚点*例如,a img=>a.img img*/ 函数给出链接图像类($html、$id、$caption、$title、$a

我正在尝试在页面上设置一个图库,以及一个lightbox效果,我将使用jQuery实现这个效果

我需要为每个图像添加一个类,这样jQuery就可以针对这个类并完成它的工作-不幸的是,我还需要这种效果来只应用于给定类别中的图像-所以用jQuery添加类是行不通的

以下是我到目前为止的代码(它不起作用):

if(在_类('gallery')){
/***将类附加到链接图像的父锚点*例如,a img=>a.img img*/
函数给出链接图像类($html、$id、$caption、$title、$align、$url、$size、$alt=''){$classes='gallery\img gllry';//以空格分隔,例如'img image link'
//检查是否已经为锚点分配了类
if(preg_match(“//”,$html)){$html=preg_replace(“/()/”,$1'$classes.$2',$html);}else{$html=preg_replace(“/”,$1 class=“”.$classes.“>”,$html)}返回$html;}添加过滤器('image_send_to_编辑器','give_linked_images u_class',10,8);
我把它放在我的主题的functions.php和nada,zilch中。它应该针对标签中的img标签,在类别“gallery”中,不是吗


非常感谢您的帮助。

通常,如果您有某个特定类别的帖子,它可能会应用类
.category ID
.category name
。您只需将样式添加到style.css文件中即可


来源:

您希望在站点上的任何图像上使用此选项,还是仅在特定于内容的图像上使用此选项?Wordpress根本不向其添加任何类,除非使用非常通用的“右”、“中”或“左”来定位元素。CSS样式对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);