一意のIDを持つビデオプレーヤーコンテナdivを動的に生成したい。要素は、ワードプレスでビジュアルコンポーザを介して生成され、最終 HTML は、このようななものになります。ユーザーは自分が好きなようユニークなIDを持つなど、多くのdiv要素を追加することができるはず動的に生成されたdivの増分ID
<div style="width: 100%; display: inline-block; position: relative;">
<div style="margin-top: '. $custom_margin .'"></div>
<div id="player_1" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>
</div>
<div style="width: 100%; display: inline-block; position: relative;">
<div style="margin-top: '. $custom_margin .'"></div>
<div id="player_2" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>
</div>
<div style="width: 100%; display: inline-block; position: relative;">
<div style="margin-top: '. $custom_margin .'"></div>
<div id="player_3" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>
</div>
を。これは私のPHPが今どのように見えるかです: EDIT:関数は、すべて単一のビデオコンテナ
public function vc_custvideo_html($atts){
extract(
shortcode_atts(
array(
'custom_width' => '',
'custom_height' => '',
),
$atts
)
);
$percent = $custom_height/$custom_width;
$custom_margin = number_format($percent * 100, 2) . '%';
$html = '';
$html.= '<div style="width: 100%; display: inline-block; position: relative;">';
$html.= '<div style="margin-top: '. $custom_margin .'"></div>';
$html.= '<div id="player_" style="position:absolute;top:0;left:0;right:0;bottom:0"></div>';
$html.= '</div>';
return $html;
}
のために呼ばれて、私はユニークなIDを生成するためにforeach
ループを使用する必要がありますが、私は本当に新しいんだということを理解することができますPHPで私は助けが必要です。
'$ atts'は**シングル**ビデオプレイヤーのデータですか? –
は、それぞれのビデオごとに、またはそれらをすべて生成するための関数 'vc_custvideo_html'です。これにより、違います – Kaddath