【发布时间】:2015-06-13 20:32:58
【问题描述】:
我目前正在使用 wordpress,并且我有一个链接应该可以播放 wav 文件,具体取决于帖子的标题。所以如果帖子标题是'one',那么它应该从上传文件夹播放one.wav。但是,每个帖子上的声音文件只播放最新的帖子标题。因此,如果我添加了一个名为 two 的帖子,然后添加了一个名为 one 的帖子,这两个帖子都会播放 one.wav。
代码如下:
HTML
<span id="dummy"></span>
<a class="playSound" onclick="playSound();" href="#">
<i class="fa fa-volume-up"></i>
</a>
jQuery
function playSound() {
$.ajax({
url: 'sound.php',
data: "getSound",
type: "GET",
datatype: "html",
success: function(data) {
document.getElementById("dummy").innerHTML= "<embed src=\""+data+"\" hidden=\"true\" autostart=\"true\"loop=\"false\" />";
}
});
}
和 PHP
<?php
require('./wp-blog-header.php');
if(isset($_GET['getSound'])) {
$file='wp-content/uploads/2015/wav/' . get_the_title() . '.wav';
echo $file;
}
?>
我认为get_the_title() 是正确的电话,但在这一点上我不太确定。我已经尝试了所有其他调用功能,但仍然没有运气。我认为此时与加载页面和存储初始帖子标题有关,但此时我只是迷路了。
【问题讨论】:
-
get_the_title() 需要 post_id codex.wordpress.org/Function_Reference/get_the_title
-
听起来你的php代码不在the loop
-
可能。我已将代码更改为仅使用 @poostchi 建议的 javascript。关于如何让它进入循环的任何建议?我假设它在第一篇文章中运行时锁定了该文件名。我对此还是很陌生。
-
如果必须知道,我的主题函数 js 文件中有函数,content.php 文件中有 html。我认为每个帖子的循环都会遍历 content.php,并认为这是一个安全的地方。
标签: php jquery html ajax wordpress