これは可能なはずです。
AJAX を使用して、ビデオ プレーヤーを含む div を生成することもできます。これを行うと、プレーヤーを非常に簡単に削除/再作成できます。
その後、ディレクトリ文字列値とブール値をショートコード ハンドラーにアタッチする関数にフィードするショートコード定義が必要になります。
例えば
$defaultDirectory= site_url() +"/videos/";
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
}
また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 "";
}
}