我已将侧栏分配到functions.php
:
register_sidebar(
array (
\'name\' => \'Footer Widgets Area\',
\'id\' => \'footer_widgets_area\',
\'description\' => \'Assign Maximum 3 widgets into this footer sidebar area.\',
\'class\' => \'my-class\',
\'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
\'after_widget\' => "</li>",
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\'
)
);
在页脚中,我想在激活的小部件数量之后将特定的CSS类加载到小部件容器中。所以我用了这个: $our_sidebar = wp_get_sidebars_widgets();
$widget_counter = count( $our_sidebar[\'footer_widgets_area\'] );
if( $widget_counter == 1 ) {
$the_class = \' widen-full\';
} elseif( $widget_counter == 2 ){
$the_class = \' widen-duo\';
} else {
$the_class = \' widen-trio\';
}
我的页脚现在正在加载的内容是:<div class="widget-area" id="footer-widget-area">
<ul class="xoxo">
<li class="widget-container widget_archive" id="archives-2">
<h3 class="widget-title">Archives</h3>
Archive Widget Content
</li>
<li class="widget-container widget_calendar" id="calendar-2">
Calendar Widget
</li>
<li class="widget-container widget_meta" id="meta-3">
Meta Widget
</li>
</ul>
</div>
请注意,如果我可以echo
我的班级$the_class
进入<li>
然后我的问题就解决了。<li class="widget-container widget_archive" id="archives-2">
虽然我经常使用WordPress,但我害怕挂钩和过滤器,在大多数情况下,我对它们有一点了解。如果有人不仅能给我提供解决方案,而且能解释与此相关的过程,那将是我更好的成就。那就是我未来的成就。PS: 不知何故,中定义的类register_sidebar()
没有回声。我不知道为什么。