将侧栏“之前”和“之后”html注册为div标记,而不是li标记

时间:2012-01-20 作者:byronyasgur

我正在使用register边栏函数为我的主题制作边栏。抄本是这样写的

if ( function_exists(\'register_sidebar\') )
register_sidebar(array(
\'name\' => \'Right Sidebar\',
\'id\' => \'right-sidebar\',
\'before_widget\' => \'<li id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</li>\',
\'before_title\' => \'<h4>\',
\'after_title\' => \'</h4>\',
));
然而Jason Tadlock 是这样的吗:

if ( function_exists(\'register_sidebar\') )
register_sidebar(array(
\'name\' => \'Right Sidebar\',
\'id\' => \'right-sidebar\',
\'before_widget\' => \'<div>\',
\'after_widget\' => \'</div>\',
\'before_title\' => \'<h4>\',
\'after_title\' => \'</h4>\',
));

ie that (causes the dynamic_sidebar function to ) output 
<ul><div> ... etc ... </div><div> ... etc ... </div></ul> 
using no <li> tags becuase of the before and after widget paramaters
我在w3c上找不到任何允许除<;li>内部标记(<);标签,但我无法想象贾斯汀·塔洛克会支持Invlad代码。

老实说,贾斯汀的方式在语义上对我来说更有意义,但我相信其他人会有所不同。我的问题是-这样做可以吗。。。。哪一个是最好的?

1 个回复
最合适的回答,由SO网友:mor7ifer 整理而成

dynamic_sidebar() 不输出a<ul>, 因此,您的代码应该如下所示:

<div id="sidebar">
    <?php dynamic_sidebar(); ?>
</div>
还有这个,还有<div> before\\u widget和after\\u widget中的标记将为您提供嵌套的div。

结束

相关推荐

Dividing widgets in sidebar?

我有一个自定义的边栏叫做页脚。我使用以下代码显示此侧栏:<?php if ( !function_exists(\'dynamic_sidebar\') || !dynamic_sidebar(\'Footer\') ) : ?> (maybe I should do something in this line?) :) <?php endif; ?> 这很顺利,但现在几乎每个主题都允许用户将其小部件放在列中,就像这样:http://ka