PHP打印文本而不是HTML

问题描述 投票:0回答:2

我有一个自定义帖子类型'Book'和两个自定义字段Author和Rate。速率可以从1到5,并且我想将字体真棒星形图标打印为“速率”字段数。但是,当我回显字体真棒图标时,它仅打印文本,而不打印图标本身。

代码:

<div class="book">
        <h3>“<?php the_title(); ?>”</h3>
        <p><?php the_field('author'); ?></p>
        <?php 
            for ($i = 0; $i < the_field('rate'); $i++)
                echo '<i class="fas fa-star"></i>';
        ?>
 </div>
php wordpress advanced-custom-fields custom-post-type
2个回答
0
投票

似乎您有错字。该课程应为“ fa fa-star”

<div class="book">
        <h3>“<?php the_title(); ?>”</h3>
        <p><?php the_field('author'); ?></p>
        <?php 
            for ($i = 0; $i < the_field('rate'); $i++)
                echo '<i class="fa fa-star"></i>';
        ?>
 </div>

0
投票

问题出在the_field函数中。它会立即打印数字,以便在迭代开始时函数打印值并停止循环。我用返回值的get_field函数替换了the_field,现在它正在工作!


0
投票

问题出在the_field函数中。它会立即打印数字,以便在迭代开始时函数打印值并停止循环。我用返回值的get_field函数替换了the_field,现在它正在工作!

© www.soinside.com 2019 - 2024. All rights reserved.