javascript - php - slider 在 WordPress 的 front-page.php 中不起作用

标签 javascript php jquery html wordpress

我在 html 代码中使用了 javascript 和 php slider ,当它进入 WordPress 时它从未工作,当它在 html 中时它工作现在它说没有找到此幻灯片的图像。

header.php JavaScript

<script>
$(document).ready(function(){
$('#myslides').cycle({
    fit: 1, pause: 0.3
});
});
</script>

front-page.php slider PHP代码

<?php
$directory = 'images/slideshow/';   
try {       
// Styling for images   
echo "<div id=\"myslides\">";   
foreach ( new DirectoryIterator($directory) as $item ) {            
    if ($item->isFile()) {
        $path = $directory . "/" . $item;   
        echo "<img src=\"" . $path . "\" height='200' width='800' />";  
    }
}   
echo "</div>";
}   
catch(Exception $e) {
echo 'No images found for this slideshow.<br />';   
}
?>

最佳答案

在 WordPress 中,您必须使用 get_template_directory() 来获取主题目录的路径,因此您的目录变量应该是:

$directory = get_template_directory() . '/images/slideshow/';

关于javascript - php - slider 在 WordPress 的 front-page.php 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33090597/

相关文章:

jquery - 切换tinymce编辑器后,它不发送complete字符串

javascript - 我试图在视频到达提示点时增加变量

javascript - 哪些选项可以使用 Google Cloud Vision 改进 OCR?

javascript - bootstrap datetimepicker 获取日期

php - 执行 PHP 程序的 Cron 作业

javascript - 如何在灯箱中添加标题或描述?

javascript - 在 ASP.NET 中验证器后显示弹出窗口

javascript - 更改使用 AJAX 加载的元素的 src

php - 上传 14000 行 csv 文件时出错

jQuery 动画回到原始位置