我正在为wordpress创建一个主题,我在我的小部件上的标题上实现图像替换时遇到问题.
我如何添加自定义类或id来包装我的小部件?
例如
HTML:
<div id="sidebar">
<div id="customWidgetId">
<h2>This Title will be replace by an Image</h2>
<p>Wordpress 'Text' Widget content here</p>
</div>
<div id="anotherCustomWidgetId">
<h2>This Title will be replace by an Image</h2>
<p>Wordpress 'Text' Widget content here</p>
</div>
<div class="customClass">
<h2>This Title will be replace by an Image</h2>
<p>Wordpress 'Text' Widget content here</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#anotherCustomWidgetId h2 {
text-indent: -1000em;
background: url of my image;
width: ;
height: ;
}
Run Code Online (Sandbox Code Playgroud)
我需要控制我的小部件的ID和类.所以我可以为小部件创建自定义css图像替换.
如果你在我的鞋子里,你将如何在wordpress中实现它?
谢谢!
如果你只是想为每个小部件添加一个类(我已经为clearfix修复完成了这个),那么在register_sidebar中添加另一行,就像这样......
register_sidebar(array(
'id' => 'sidebar1',
'name' => 'Sidebar (Main)',
'description' => 'Primary sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
'class' => 'clearfix'
));
Run Code Online (Sandbox Code Playgroud)
这为我的所有小部件添加了一类'clearfix'.