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条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装