【问题标题】:Wordpress sidebar classesWordpress 侧边栏类
【发布时间】:2010-06-04 15:08:43
【问题描述】:

有什么方法可以为小部件项目的特定顺序添加一个类?即类名是 widgetorder-1(用于第一个出现的小部件)、widgetorder-2(用于以第二个顺序出现的小部件)等。我查看了过滤器,但不确定它是如何工作的。

【问题讨论】:

    标签: css wordpress class sidebar


    【解决方案1】:
    // Set this to whatever number you'd like the ordering to start on.
    $my_blog_widget_count = 0;
    // put your blog sidebar here
    $my_blog_sidebar_id = '';
    
    function output_my_widget_info($a){
        global $my_blog_sidebar_id, $my_blog_widget_count;
        if($a[0]['id'] == $my_blog_sidebar_id){
            global $my_blog_sidebar_id, $my_blog_widget_count;
            $a[0]['before_widget'] = preg_replace( '/ class="widget /i', ' class="widget widget-'.$my_blog_widget_count.' ', $a[0]['before_widget'] );
            $my_blog_widget_count++;
        }
        return $a;
    }
    
    add_filter('dynamic_sidebar_params','output_my_widget_info');
    

    这应该为你做。只需将其粘贴在主题的 functions.php 文件中并观察它的工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-22
      • 2020-08-23
      • 2016-08-17
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多