请按此处查看图片
在这个图像中,黑点是背景图像上的另一个图像。我可以把那个黑点嵌入到那个post image
$embedCode ='div id="mainCHImage"style="position:relative;height:'.$heightOrg.'px;width:'.$widthOrg.'px;">'.
'<img style="background:none;border:none;height:'.$heightOrg.'px !important;width:'.$widthOrg.'px !important;"'. "src='"{$matches[1]}'";>".'
</div>
<img id="Icon" style="position:relative;left:'.$imgWidth.'px;top: '.$imgHeight.'px;padding-left: 10px;z-index:9999;cursor:pointer;background:none;border:none;" src="/Icon.png" onClick="showProducts(event,'."'{$matches[1]}'".')"></div>
这是代码,我要替换后图像的图像,以便在该背景图像上带来黑点。现在的问题是黑点的onclick,我想运行一个javascript函数,但在wordpress中,它被包裹在背景图像的href锚标签下,因此没有得到点击事件。但我已经禁用了图像上的链接,然后它的工作,但它不是正确的方式。下面我将粘贴这段代码的inspect元素响应…
<a href="http://localhost/wordpress/wp-content/uploads/2013/04/9.jpg">
<img id="Icon" style="position:relative;left:130px;top: -30px;padding-left: 10px;z-index:9999;cursor:pointer;background:none;border:none;"
src="/Icon.png" onclick="showProducts(event,'http://localhost/wordpress/wp-content/uploads/2013/04/9.jpg')">
我不知道锚标签是从哪里来的…
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
$content =preg_replace(array('{<a(.*?)(wp-att|wp-content'/uploads)[^>]*><img}','{ wp-image-[0-9]*" /></a>}'),array('<img', '" />'), $content);
return $content;
}
/*place this code in your functions.php*/
/*if you wanna remove anchor tags which has image links, follow below code*/
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
global $post;
$exceptional_cjtypes = array("Mashup");
$cjtype = wp_get_post_terms($post->ID, "cjtype");
if(!in_array(strtolower($cjtype[0]->name), array_map('strtolower', $exceptional_cjtypes))) {
$content =preg_replace(
array('{<a href="(.*?(gif|jpeg|jpg|png))"><img}',
'{ wp-image-[0-9]*" /></a>}'),
array('<img', '" />'),
$content
);
}
return $content;
}