【问题标题】:ACF Content Not ShowingACF 内容未显示
【发布时间】:2022-11-14 05:10:20
【问题描述】:

我已经为 Wordpress 用户页面文本和图像创建了 ACF 字段当我尝试在 single.php 上显示时,它没有显示下面的图像或文本,这是供参考的屏幕截图。

https://prnt.sc/ezFU-JPZH3Rs

 <ul class="list-unstyled">
                            <li>
                                <div class="row">
                                    <div class="col-4">
                                        <div class="home-blog-author">
                                            <?php
                                             $avatar_image= get_field('user_image', 'user_'. $author_id );
                                            ?>
                                            <picture>
                                                <img src="<?php echo $avatar_image['url']; ?>" class="img-fluid" alt="<?php echo $avatar_image['alt']; ?>">
                                            </picture>
                                        </div>
                                    </div>
                                    <div class="col-8 align-self-center ps-0">
                                        <div class="home-author-name">
                                            <h5><?php //echo the_field('user_name', 'user_' .$author_id); ?></h5>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <i class="fas fa-calendar-alt"></i>
                                <span><?php echo get_the_date('d/m/Y'); ?></span>
                            </li>
                        </ul>

【问题讨论】:

  • 你是如何设置$author_id 的,你有没有检查过这个值以确保它映射到一个有数据的作者?
  • $author_id = get_the_author_meta('ID');

标签: php html wordpress advanced-custom-fields


【解决方案1】:

您知道在您的 sn-p 中您已将名称文本注释掉,对吗?否则,您将有多个可能的故障点。在我的头顶上:

  1. 您确定要按预期重新调整 html(有或没有 ACF 数据)吗?如果没有,那么您可能有错误的模板或其他问题。如果是这样:
  2. 您确定将 ACF user_image 字段设置为返回一个数组 - 特别是对于您正在测试的用户吗?
  3. 您是否尝试通过键而不是字段名称返回 ACF 字段?这有时会有所帮助。

【讨论】:

    猜你喜欢
    • 2018-01-10
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多