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 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案