함수 get_post_types('', 'names')
은 게시물 유형의 이름을 포함하는 배열을 반환합니다.HTML 드롭 다운에 PHP 배열을 삽입하려면 어떻게해야합니까?
<?php
$post_types = get_post_types('', 'names');
foreach ($post_types as $post_type) {
echo '<p>' . $post_type . '</p>';
}
?>
함수 get_post_types('', 'names')
은 게시물 유형의 이름을 포함하는 배열을 반환합니다.HTML 드롭 다운에 PHP 배열을 삽입하려면 어떻게해야합니까?
<?php
$post_types = get_post_types('', 'names');
foreach ($post_types as $post_type) {
echo '<p>' . $post_type . '</p>';
}
?>
다운 내측 <option>
태그와 <select>
태그를 사용하여 생성되는 HTML
드롭.
배열을 반복하고 <option>
태그를 인쇄 할 수 있습니다.
예.
$post_types = get_post_types('', 'names');
echo "<select>";
foreach($post_types as $post_type) {
echo "<option value='{$post_type}'>{$post_type}</option>";
}
echo "</select>";
는 드롭 다운을 만들 수 <select>
HTML 요소를 사용하여 <option>
드롭 다운에 항목을 만들 :
<?php
$post_types = get_post_types('', 'names');
echo '<select>';
foreach ($post_types as $post_type) {
echo '<option>' . htmlspecialchars($post_type) . '</option>';
}
echo '</select>';
?>
PS : HTML 문서에 텍스트를 삽입 할 때, 당신은 항상 htmlspecialchars
를 사용한다 그렇지 않으면 XSS attacks이 될 수 있습니다.
PHP를 배워야합니다. – PHPglue
그는 HTML로 시작해야합니다. – noahnu