wordpress - Wordpress,在短代码中插入 URL
问题描述
我正在尝试在下面的短代码中显示/插入一个 url:
<?php echo do_shortcode('[sc_embed_player fileurl="http://www.example.com/wp-content/uploads/my-music/mysong.mp3"]'); ?>
我正在使用一个名为“add_audio”的 ACF 字段,它是一个 mp3 URL。
我使用默认的获取字段 ( <?php the_field('field_name'); ?>
) 代码来调用 url。
我也做了一个变量并调用了 ($variable) 。
但是没有任何效果!!
这是我得到的错误
“Prase 错误:语法错误,意外的 'add_audio'(T_STRING),期待,''or')' in /app/public/wp-content/oxygen/component-framework/components/layouts/code-block.php(33 ):eval()'d 代码在第 43 行"
我使用了 Oxygenbuilder 插件和 ACF 插件。
<?php
/*
* Easy Query Shortcode
* [easy_query container="div" template="template_906184" posts_per_page="20" post_type="audio_files"]
*/
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => array('audio_files'),
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => 20,
'paged' => $paged,
);
// WP_Query
$eq_query = new WP_Query( $args );
if ($eq_query->have_posts()) : // The Loop
$eq_count = 0;
?>
<div class="wp-easy-query paging-style-default grey">
<div class="wp-easy-query-posts">
<div>
<?php
while ($eq_query->have_posts()): $eq_query->the_post();
$eq_count++;
?>
<div id="div_block-17-25" class="ct-div-block audio-div">
<h1 id="headline-18-25" class="ct-headline">
<?php the_title(); ?></h1>
<div id="div_block-20-25" class="ct-div-block">
<?php echo do_shortcode('[sc_embed_player_template1 fileurl="<?php the_field('add_audio'); ?>"]'); ?>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
<?php include(EQ_PAGING); ?>
</div>
<?php endif; ?>
解决方案
只需尝试从您的代码中删除,如下所示:
<?php echo do_shortcode('[sc_embed_player_template1 fileurl="'.the_field('add_audio').'"]'); ?>