在前端显示高级自定义字段的内容

时间:2021-07-26 15:57:34

标签: php woocommerce advanced-custom-fields

我在让自定义字段显示在页面上时遇到问题。我在 Woo Commerce 中使用它们来显示有关产品的信息。我一直在研究,我发现的建议都没有奏效。我什至尝试了一个 ACF 代码生成器,它有很好的评价,但是当我将代码放入我的子主题的 functions.php 时,它使我的网站崩溃。我不确定我做错了什么和/或我应该从哪里开始。 (另外,我有 PHP 的基本知识,但仅此而已。

我也尝试过使用简码来调用我需要它们的页面上的字段,但这也不起作用。

代码如下:

<?php if ( have_rows( 'product_code' ) ) : ?>
    <?php while ( have_rows( 'product_code' ) ) : the_row(); ?>
        <?php the_sub_field( 'top_features' ); ?>
        <?php the_sub_field( 'features' ); ?>
        <?php the_sub_field( 'description' ); ?>
        <?php the_sub_field( 'specifications' ); ?>
        <?php if ( have_rows( 'manuals_&_docs' ) ) : ?>
            <?php while ( have_rows( 'manuals_&_docs' ) ) : the_row(); ?>
                <?php $ = get_sub_field( '' ); ?>
                <?php if ( $ ) : ?>
                    <?php $url = wp_get_attachment_url( $ ); ?>
                    <a href="<?php echo esc_url( $url ); ?>">Download File</a>
                <?php endif; ?>
                <?php $ = get_sub_field( '' ); ?>
                <?php if ( $ ) : ?>
                    <?php $url = wp_get_attachment_url( $ ); ?>
                    <a href="<?php echo esc_url( $url ); ?>">Download File</a>
                <?php endif; ?>
            <?php endwhile; ?>
        <?php endif; ?>
        <?php if ( have_rows( 'sds_safety_data_sheets' ) ) : ?>
            <?php while ( have_rows( 'sds_safety_data_sheets' ) ) : the_row(); ?>
                <?php $ = get_sub_field( '' ); ?>
                <?php if ( $ ) : ?>
                    <a href="<?php echo esc_url( $['url'] ); ?>"><?php echo esc_html( $['filename'] ); ?></a>
                <?php endif; ?>
                <?php $ = get_sub_field( '' ); ?>
                <?php if ( $ ) : ?>
                    <a href="<?php echo esc_url( $['url'] ); ?>"><?php echo esc_html( $['filename'] ); ?></a>
                <?php endif; ?>
            <?php endwhile; ?>
        <?php endif; ?>
        <?php the_sub_field( 'video' ); ?>
    <?php endwhile; ?>
<?php endif; ?>

0 个答案:

没有答案