代码之家  ›  专栏  ›  技术社区  ›  EMILY MARCIANO

如何在我的博客页面中多次使用i20边栏小部件WordPress插件?[关闭]

  •  -2
  • EMILY MARCIANO  · 技术社区  · 6 月前

    [i20_Sidebar_Widgets]

    .border-onestop{overflow-y:scroll;border:1px solid #C1C1C1;padding:8px 2px 0 8px;height:520px;width:100%;}
    .noborder-onestop {overflow-y: scroll;height: 520px;width: 100%;}
    .entrytitle{line-height: 1.2;margin-bottom: 5px;}
    .entrydescrip{font-size:16px;color:#000;line-height:1.3;margin-bottom:6px;clear: both;}
    .entrydescrip_lg{font-size:16px;color:#000;line-height:1.4;margin-bottom:6px;clear: both;}
    .osclearfix{clear:both;}
    .entryimg{float:left;margin-right:8px;}
    .entryimg img{width:112px;height:auto;}
    .entryimg_b{margin-right:8px;}
    .widgettextsize { font-size:18px; }
    .widgettextsize_lg { font-size:22px; }
    .widgettextsizemar { font-size:17px;margin-bottom: 12px; }
    .widgettextsizemar_lg { font-size:18px;margin-bottom: 12px; }
    

    register_setting(
                'itsw_plugin_options_group',
                'itsw_height_of_i20_sidebar',
                array(
                    'type'              => 'integer',
                    'sanitize_callback' => 'sanitize_text_field',
                )
            );
    

    那么如何为不同的Widget生成不同的高度。

    1 回复  |  直到 6 月前
        1
  •  0
  •   user1846871    6 月前

    您可以添加短代码属性

    修改插件中的短代码回调,使其支持以下参数:

    [i20_Sidebar_Widgets高度=“400”宽度=“350”]

    将此添加到您的shortcode函数中:

    function i20_sidebar_widgets_shortcode($atts) {
        $atts = shortcode_atts(
            array(
                'height' => '',
                'width'  => '',
            ),
            $atts,
            'i20_Sidebar_Widgets'
        );
    
        $height = !empty($atts['height']) ? $atts['height'] : get_option('itsw_height_of_i20_sidebar');
        $width  = !empty($atts['width']) ? $atts['width'] : '100%';
    
        ob_start();
        ?>
        <div class="border-onestop" style="height:<?php echo esc_attr($height); ?>px; width:<?php echo esc_attr($width); ?>;">
            <!-- widget content -->
        </div>
        <?php
        return ob_get_clean();
    }
    add_shortcode('i20_Sidebar_Widgets', 'i20_sidebar_widgets_shortcode');
    
    
    Then you can use shortcode like:
    Category page:
    [i20_Sidebar_Widgets height="600" width="100%"]
    
    Tag page:
    [i20_Sidebar_Widgets height="500" width="80%"]
    
    Single post page:
    [i20_Sidebar_Widgets height="450" width="100%"]
    
    
    This will not affect each other, because each shortcode instance has its own inline style.