首页 > 解决方案 > 包括

endforeach 语句后的标记

问题描述

所以我希望能够<p></p>在下面的 foreach 语句的末尾包含一个 using html 标签,但我一直遇到代码问题。

图片在此处输入图像描述

代码

    <?php if(!empty($mediaUrls)):
        if(is_front_page() || is_home()):
            $counter = 0;
            foreach($mediaUrls as $entry):
                $counter++;
                $mediaurl = $entry['media_url'];
                $permalink = $entry['permalink'];

                if($counter > 6) {
                    break;
                }
                ?>
                <article class="tw-status">
                    <div class="tw-content">
                        <a href="<?= $permalink; ?>" target="_blank"><img alt="" class="insta_image" src="<?= $mediaurl; ?>" width="100%"/></a>
                    </div>
                </article>
            <?php endforeach;
            endif;
        else:
            echo 'No posts available.';
        endif;
    ?>

标签: php

解决方案


您需要先关闭PHP,然后才能添加P标签,如下所示:

  <?php if(!empty($mediaUrls)):
        if(is_front_page() || is_home()):
            $counter = 0;
            foreach($mediaUrls as $entry):
                $counter++;
                $mediaurl = $entry['media_url'];
                $permalink = $entry['permalink'];

                if($counter > 6) {
                    break;
                }
                ?>
                <article class="tw-status">
                    <div class="tw-content">
                        <a href="<?= $permalink; ?>" target="_blank"><img alt="" class="insta_image" src="<?= $mediaurl; ?>" width="100%"/></a>
                    </div>
                </article>
            <?php endforeach; ?>
            <p></p>
            <?php
            endif;
        else:
            echo 'No posts available.';
        endif;
    ?> 

希望它可以帮助你。


推荐阅读