가능해야합니다.
AJAX를 사용하여 동영상 플레이어가 포함 된 div를 생성하는 것이 좋습니다. 이렇게하면 플레이어를 아주 쉽게 삭제/다시 만들 수 있습니다.
그런 다음 단축 코드 처리기에 첨부하는 함수에 디렉토리 문자열 값과 부울 값을 제공하는 단축 코드 정의가 필요합니다.
$ defaultDirectory = site_url() + "/ 비디오 /"예를 들어
; http://php.net/manual/en/function.readdir.php
<?php
/**
* get the number of files within a given dir
*/
function fileCounter($dir){
$counter = 0;
if ($handle = opendir($dir)) {
//echo "Directory handle: $handle\n";
//echo "Files:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
//echo "<BR>".$counter." - $file";
$counter++;
}
closedir($handle);
}
$counter -= 1; // in order to exclude '.' and '..', as well as start the counter on 1
return $counter;
}
/**
* get the filename in a giver dir, starting the first file with the index 1
*/
function fileNameByIndex($dir, $fileIndex){
$counter = 0;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$counter++;
if($counter - 2 == $fileIndex)
return $file;
}
closedir($handle);
}
return "";
}
}
에서도
add_shortcode('video', 'videoDiv');
function videoDiv($shortcodeAttributeList)
{
extract(shortcode_atts(array(
'src' => $defaultDirectory,
'random' => true, /*set default values, use lowercase*/
), $shortcodeAttributeList));
if($random)
{
$numFiles=fileCounter($src);
$choice=rand(1, $numFiles);
}
$output='<div id="videoPlayer" class="player">';
// Continue by making a string which spans from <div> to </div>
return $output; //a div
}