简体   繁体   中英

php - Slider not working in front-page.php in wordpress

I was using a javascript and php slider in html code when it went into wordpress it never worked when it was in html it worked now it says No images found for this slideshow.

header.php javascript

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

front-page.php slider php code

<?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/';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM