在我的WP主题中,我希望能够在我的single.php中定位(挂起我的style.css中的css)图像和内容。
在single.php上,它通过循环放入内容
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php bnNav_content_nav( 'nav-below' ); ?>
<?php endwhile; // end of the loop. ?>
和content-single.php
<div class="container"
<?php the_content(); ?>
</div>
帖子的内容有图像和文字,但都以&lt;&lt; p>标签。我可以对图像进行定位,以便能够添加-margins(凌乱,但我可以为文本设置不同的边距)但是我想为每个添加更多独特的样式
答案 0 :(得分:0)
似乎没有从post body抓取媒体的具体功能。您可以在帖子内容中使用regex for wrapping/handling images,或者只使用这样的CSS来执行此操作:
.container p img {
/*styles here*/
}
此外,由于您提到了jQuery,您可以使用相同的选择器方式访问帖子图像节点列表:
$('.container p img').each(function(){
//$(this) is and <img tag
})
答案 1 :(得分:0)
您的图片不必包含在段落中。您可以在文本模式下使用WordPress编辑器将图像包装在DIV中。
通过这种方式,您可以分别为图像和段落定义DIV的样式。如果您经常需要此功能,您可以自行准备一个快速标签,即使在编辑器中也可以快速插入带有图像的div
。视觉模式。
AddQuicktag-Plugin是一个很好的工具。