dty9731 2015-12-19 19:54
浏览 122

如何使用嵌入JavaScript的PHP播放音频onclick?

I have Wordpress site for my podcast. I have set up a preview button (using span) with a short audio file to accompany each post in a category. The audio files are called with a custom post field, "audio_preview".

I would like to set the button to play audio files on-click. For now, clicking a button will exit the current page and redirects to the file itself. Here's an example page and the button's code.

<span class="entry-preview-button"><a class="entry-preview-button" href="<?php echo get_post_meta($post->ID, 'audio_preview', true); ?>"><i class="fa fa-volume-down"></i> Preview</a></span>

It appears I need to use JavaScript's onclick function to do this. However, my problem is this bit of PHP.

<?php echo get_post_meta($post->ID, 'audio_preview', true); ?>

Things go wrong when I try to enclose the button in a script. I've tried modifying the code to the extent of my abilities, including using input tags instead of span tags. The best I can do is have one file play for every button on the page instead of the respective files.

What am I missing?

  • 写回答

1条回答 默认 最新

  • dongzilu0178 2015-12-20 00:37
    关注

    I recommend to use this plugin : https://wordpress.org/plugins/compact-wp-audio-player/ , or there are a few similar ones.

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题