dsmnedc798226 2014-11-17 18:21
浏览 90
已采纳

WordPress高级自定义字段 - 使用数组中的选择字段和修改数组元素

I'm working on a WordPress website. I am using the ACF Pro plugin. I have a select field and I want to assign a second value to each option. The first value is being used as a heading. The second is a percentage figure (at the moment just a string). This will be used as a label as well as a data-percentage value. I cant get the select values to work with my array. Here is my code.

 <h4>Qualification: <?php echo $array_test; ?></h4>

And then the array;

        <?php
            $myArray = array('$array_tests');
            $myArray[0]= '20%';
            $myArray[1]= '40%';
            $myArray[2]= '60%';
            $myArray[3]= '80%';
            $myArray[4]= '100%';

            echo "<h1> Test:";  
            echo $myArray;
            echo "<h1>";                    

        ?>

And finally using the modified array's output as a data-percentage;

<div class="skillbar clearfix" data-percent="<?php echo $myArray ?>%">
  • 写回答

2条回答 默认 最新

  • dtbhp60824 2014-11-19 17:35
    关注

    So i have assigned this variable to my select custom field.

    $staff_qualification    = get_sub_field('qualification');
    

    I use it for the title.

    <h4>Qualification: <?php echo $staff_qualification; ?></h4>
    

    And I created a switch so that I now have a new value assigned to each option from the dropdown select.

            <?php
    
            switch ($staff_qualification) {
            case "NVQ Level 1":
              $staff_qualification_percentage = 20;
              break;
            case "NVQ Level 2":
              $staff_qualification_percentage = 40;
              break;
            case "NVQ Level 3":
              $staff_qualification_percentage = 60;
              break;
            case "NVQ Level 4":
              $staff_qualification_percentage = 80;
              break;                                
            case "Degree In Childcare":
              $staff_qualification_percentage = 100;
              break;
            }                      
        ?>
    

    And now I echo the variable used in each case as my data-percentage value.

    <div class="skillbar clearfix" data-percent="<?php echo $staff_qualification_percentage; ?>%">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误