我有一個滑塊(flexslider),我用來顯示圖像顯示在下面的jsfiddle顯示圖像...我優化了滑塊,以便它從一個特定的目錄動態提取圖像。它工作並且所有圖像都被提取出來。 現在我的文件夾中的圖像被命名爲1023,2045,304654,50等... 我怎樣才能指定圖像開始讓我們說「1」(可以是14,1040,10000.100000等...)是隻提取?基於ID提取圖像
更新(更多說明):我基於每個圖像的名稱的第一個數字提取的原因是,因爲我要在我的菜單的所有元素中使用滑塊。因此,如果我點擊元素「aaaa」以1開頭的圖像出現,如果我點擊「bbbbbb」以2開頭的圖像出現,依此類推。
的jsfiddle:https://jsfiddle.net/atkumqpk/1/
PHP代碼:
function get_slide_images($folder, $images_per_slide = 10)
{
$slide_images = false;
if (file_exists($folder)) {
// valid extensions
$extensions = array(
"jpg",
"gif",
"jpeg",
"svg",
"png",
"bmp"
);
foreach (new DirectoryIterator($folder) as $file_key => $file) {
// Don't bother
if (!in_array($file->getExtension(), $extensions)) {
continue;
}
// Grab file details
$filename = $file->getFilename();
$file_folder = $folder . "/" . $filename;
// Store the image to the Slide
$slide_images[$filename] = "<img src='{$file_folder}' alt='{$file_folder}' />";
}
if (!empty($slide_images)) {
ksort($slide_images);
$slide_images = array_chunk($slide_images, $images_per_slide);
}
}
return $slide_images;
}
//end of php
<div id="logo" class="logo" ><img src="logo.png"/></div>
<p class="custom-class"><a href="">Go to the main website</a></p>
<div id="menu" class="menu">
<ul class="headlines">
<li id="item1">
<button>aaaaaaaa</button>
</li>
<li id="item2">
<button>bbbbbbb</button>
</li>
<li id="item3">
<button>ccccccc</button>
</li>
<li id="item4">
<button>dddddddd</button>
</li>
<li id="item5">
<button>eeeeeee eee.</button>
</li>
<li id="item6">
<button>ffffff</button>
</li>
<li id="item7">
<button>ggggggg</button>
</li>
</ul>
</div>
<div id="container">
<div id="first" class="inner-container">
<div id="item11" class="item"> <a name="item11"></a>
<div class="flexslider">
<ul class="slides">
$slider_kvp = get_slide_images("images", 10);
/**
* Here we are going to generate the SLIDES
*/
if($slider_kvp) {
$slider_list_html = array();
foreach($slider_kvp as $slider_key => $slide_images) {
$html_LI_list = "";
$html_LI_list = "<li>";
// Go through each image ...
foreach($slide_images as $image_key => $image_value) {
$html_LI_list .= $image_value;
}
$html_LI_list .= "</li>";
$slider_list_html[$slider_key] = $html_LI_list;
}
// OUR SLIDES!
$rendered_slider_list_html = implode(' ', $slider_list_html);
echo "<ul class='slides'>{$rendered_slider_list_html}</ul>";
}
</ul>
</div>
</div>
</div>
<div id="second" class="inner-container">
<div id="item22" class="item"> <a name="item22"></a>
<div class="flexslider">
<ul class="slides">
$slider_kvp = get_slide_images("images", 10);
/**
* Here we are going to generate the SLIDES
*/
if($slider_kvp) {
$slider_list_html = array();
foreach($slider_kvp as $slider_key => $slide_images) {
$html_LI_list = "";
$html_LI_list = "<li>";
// Go through each image ...
foreach($slide_images as $image_key => $image_value) {
$html_LI_list .= $image_value;
}
$html_LI_list .= "</li>";
$slider_list_html[$slider_key] = $html_LI_list;
}
// OUR SLIDES!
$rendered_slider_list_html = implode(' ', $slider_list_html);
echo "<ul class='slides'>{$rendered_slider_list_html}</ul>";
}
</ul>
</div>
</div>
</div>
你必須在'1023,2045,304654名圖像,50'所以你
get_slide_images
功能可能看起來像。好的。那麼'1'是什麼,你想做什麼? –@PraveenKumar圖像被命名爲不同的數字,我想根據其fulll數字的第一個數字來提取它們。例如:10,154,10056,1304 ...被提取,因爲它們以1開頭。 – mikeb
發生了什麼?用你的代碼? –