滑块不工作在首页.php在wordpress

Slider not working in front-page.php in wordpress

本文关键字:首页 wordpress php 工作      更新时间:2023-09-26

我在html代码中使用javascript和php滑块,当它进入wordpress时它从来没有工作,当它在html中工作,现在它显示没有找到这个幻灯片的图像。

header。php javascript

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

首页。PHP滑块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/';