我在 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/