详情
评论
问答

卡片列表个数修改代码

//卡片模式美化
CSF::createSection($prefix, array(
    'label'   => '当首页默认模式不为卡片模式时,此开关无效(仅对pc端有效)',  
    'id'      => 'card',
    'title'       => '卡片模式美化',
    'icon'        => 'fa fa-linode',
    'description' => '',
    'fields'      => array(
        array(
            'title'   => '启用卡片模式美化',
            'id'      => 'card_switcher',
            'class'   => 'compact',
            'type'    => 'switcher',
            'default' => false,
            'desc'    => '开启后,首页将以卡片模式展示,并可设置每行显示个数',      
        ),
        array(
           'title'   => '每行显示个数', 
           'id'      => 'card_num',
           'type'    => 'number',
           'default' => 4,
            'min'     => 3,
            'max'     => 5,
            'step'    => 1,
            'unit'    => '个',
            'type'    => 'spinner',

        ),
    ),
));

 

// 编写一个函数,用于卡片模式美化
function child_card_num_function() {            
    if (_child('card_num')) {
        return _child('card_num');
    } else {
        return 3; // 默认值
    }
}
function child_card_function() {            
 if (_child('card_num')) {              
      echo '<style>
    @media only screen and (min-width: 1200px){.posts-item.card {
                width: calc(' . (100.000000/_child("card_num")) . '% - ' . (80/_child("card_num")) . 'px);
            }}</style>';
 }
}       
add_action('wp_head','child_card_function');

 

温馨提示:本文最后更新于2025-10-28 14:37:11,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 轩玮博客
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容