WordPress:动态更改侧边栏小部件的标题
是否可以获取我在侧边栏中启用的小部件的标题,以便我可以将其插入作为我的类属性的名称?
例如: 'before_title'=>;
',
如果我检查该元素,我想看到:
和
等...
等...谢谢
Is it possible to get the title of the widgets that I have enabled in my sidebar so I can insert that as a name for my class attribute?
For example:'before_title' => <h2 class="title of the widget">',
If I inspect the element, I want to see:<h2 class="author">
and <h2 class="links">
etc...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这绝对是可能的,但如果你想动态地做到这一点,你需要使用过滤器。
dynamic_sidebar_params
过滤器应该适合您。如果您不熟悉过滤器的功能,基本上过滤器允许您在内容显示在屏幕上或保存在数据库中之前对其进行编辑。在此处查看更多信息:http://codex.wordpress.org/Plugin_API/Filter_Reference在
dynamic_sidebar_params
过滤器,传递的数组具有以下结构(我通过 print_r 得到这个)所以这意味着,您所要做的就是在返回之前编辑
$params
数组。您可能还需要执行一些条件逻辑才能获得您想要的确切类,但我将把它留给您。这是一个例子:
It's definitely possible, but if you want to do it dynamically, you'd need to use a filter.
The
dynamic_sidebar_params
filter should work for you. If you're unfamiliar with what filters do, basically a filter allows you to edit content before it's displayed on screen or saved in the database. See more here: http://codex.wordpress.org/Plugin_API/Filter_ReferenceIn the
dynamic_sidebar_params
filter, the passed array has the following structure (I got this from doing a print_r)So that means, all you have to do is edit the
$params
array before returning it. You might have to do some conditional logic as well to get the exact class that you want, but I'll leave that up to you.Here is an example: