我正在研究Wordpress主题,并且要求是这样的。
在打印页面内容时,将DIV包装<div class="image-wrapper">
添加到所有图像。我已经做了。
在打印页面内容时,将DIV包装器添加到除图像之外的其他文本DIV包装器<div class="text-wrapper">
这样做的目的是我想应用一个样式,以便除了图像之外的所有文本都有左右边距。
我为在图像上添加包装器而创建的过滤器就是这样的
// Remove P Tags from image
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
// Wrap images with DIV
function filter_images($content){
return preg_replace('/<img (.*) \/>\s*/iU', '<span class="the-image"><img \1 /></span>', $content);
}
add_filter('the_content', 'filter_images');
但我不知道如何进行第二项任务,即将DIV包装器添加到其余内容中。