drgd73844 2017-01-03 17:16
浏览 66

使用if语句嵌套PHP

I have some PHP code

<div class="pod-b footer-pod">
            <h3 class="footer-title">Our Contacts</h3>
            <?php   
            $teachers = tribe_get_organizers_custom();  
            ?>

                <?php foreach ($teachers as $teacher){

                    // vars
                    $id = $teacher -> ID;
                    $title = $teacher -> post_title;
                    $yogaName = get_field('yoga_name', $id);
                    $phone = tribe_get_organizer_phone($id);
                    $email = tribe_get_organizer_email($id);
                ?>
    <?php
    if (!get_field('hide_the_teacher_bio_on_this_event')) {

        <div class="teacher id_<?php echo $id; ?>">
                        <h4 class="teacher-name"><?php if($yogaName){echo $yogaName;}else{echo $title;}  ?></h4>
                        <div class="teacher-phone"><i class="ion-android-call"></i><?php echo $phone;  ?></div>
                        <div class="teacher-email"><i class="ion-ios-email"></i><a href="mailto:<?php echo $email;  ?>"><!--<?php echo $email;  ?>-->Email me</a></div> 
                    </div>

                }?>
        </div>

(updated) - I am trying to wrap the div with the class of "teacher (id)" in an if statement - but am getting the openign and closing PHP syntax wrong somehow.

Any help much appreciated, thank in advance!

  • 写回答

2条回答 默认 最新

  • dongshuobei1037 2017-01-03 17:34
    关注

    Are you trying to print one record or a bunch of records? Your usage of a for loop suggests that you are trying to print a set of values for each teacher.

    There are a number of ways of making this work.

    a) The quick and dirty way: Wrap your entire HTML content and echo it by iterating through the values.

    Eg: for each ($teachers as $keyteacher => $valueteacher) {
    $yoganame = get_field('yoga_name',$valueteacher['id']);
    if ($yoganame != "") {
    echo "<div class=techer_id_$valueteacher['id']...... so on and so forth"
      }
    }
    

    b) The preferred way (how I would do it) is to return the values as an array and use jQuery / javascript to write out the HTML elements.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口