如何在每个WordPress帖子图片周围添加Div( [关闭])

关闭。这个问题需要细节或明确性。它当前不接受答案。
想改善这个问题吗?添加细节并通过编辑此帖子来澄清问题。
5年前关闭。
我想在wordpress博客文章上发布的每个图像周围添加一个div。我该怎么做?
(对于好奇的用户, 我试图在用户将鼠标悬停在图像上方时弹出一些共享按钮)。
#1【如何在每个WordPress帖子图片周围添加Div( [关闭])】将以下代码片段添加到你的functions.php文件中:

add_filter( 'image_send_to_editor', 'wp_image_wrap_init', 10, 8 ); function wp_image_wrap_init( $html, $id, $caption, $title, $align, $url, $size, $alt ) { return '< div id="wp-image-wrap-'. $id .'" class="wp-image-wrap"> '. $html .'< /div> '; }

#2这样就解决了所有问题:)!谢谢你们在这里的帮助。希望对其他人有用。
function breezer_addDivToImage( $content ) { // A regular expression of what to look for. $pattern = '/(< img([^> ]*)> )/i'; // What to replace it with. $1 refers to the content in the first 'capture group', in parentheses above $the_url = the_permalink(); $replacement = '< div class="imgWrap"> $1 < div class="imgDescription"> < div class="theShareLinks"> < img src="http://localhost/mysite/wp-content/uploads/2014/08/dfc2.png" /> < a href="http://twitter.com/share?text=& url='.get_the_permalink() .'" class="img-twitter" title="Share on Twitter" target="_blank"> < /a> < a href="http://www.facebook.com/sharer.php?u='.get_the_permalink() .'?" class="img-facebook" title="Share on Facebook" target="_blank" onclick="window.open(this.href, \'newwin\', \'width=500, height=200\'); return false; " > < /a> < a href="https://plus.google.com/share?url='.get_the_permalink() .'" class="img-google" title="Share on Google" target="_blank"> < /a> < /div> < /div> < /div> '; // run preg_replace() on the $content $content = preg_replace( $pattern, $replacement, $content ); // return the processed content return $content; }add_filter( 'the_content', 'breezer_addDivToImage' );

#3如果看起来很简单, 只需切换到文本编辑器, 或禁用视觉编辑器, 然后在插入的每个图像周围添加div。给他们所有相同的类, 然后在样式表中为该类添加样式。
-或者, 如果你想将此应用到你的Wordpress安装上的所有页面(页面, 帖子, 档案, 类别等):-
深入FTP, 并开始查看主题文件夹和文件。
你拥有用于不同视图的不同页面。 attachment.php, page.php等。根据你要更改的视图, 这些文件将包含与以下内容类似的一行:
< p class="attachment"> < a href="http://www.srcmini.com/< ?php echo wp_get_attachment_url( $post-> ID ); ?>" title="< ?php the_title(); ?> " rel="attachment"> < img src="http://www.srcmini.com/< ?php echo $att_image[0]; ?>" width="< ?php echo $att_image[1]; ?> " height="< ?php echo $att_image[2]; ?> " class="attachment-medium" alt="< ?php $post-> post_excerpt; ?> " /> < /a> < /p>

或任何提及的地方
< img src="http://www.srcmini.com/< ?php echo $att_image[0]; ?>" />

只需在其周围添加一个div, 然后在样式表中添加样式规则即可。

    推荐阅读