我正试图找到一种方法,在我创建的自定义管理页面中添加可重复的字段。
代码:
/*WordPress Menus API.*/
function add_new_menu_items()
{
add_menu_page(
"Theme Options",
"Theme Options",
"manage_options",
"theme-options",
"theme_options_page",
"",
100
);
}
function theme_options_page()
{
?>
Theme Options有什么方法使advertising_code输入可重复吗?
谢谢
发布于 2020-05-10 17:17:11
这不是最好的解决方案,但也许它对你自己的解决方案是有帮助的。
function display_ads_form_element()
{
// get the total number of "advertising codes" from the database
// the default value is 1
$codes = array('1' => '' );
if( get_option('advertising_code') !== FALSE ) {
$codes = get_option('advertising_code');
}
?>
$code): ?>
square brackets means the data will send as array // ?>
is only an easy way that the js can detect the last key // ?>
function add_new_ad_code() {
// detect the last li element
const last_li = document.getElementById('advertising_code_list').lastElementChild;
// get the listKey from the input field
const new_key = parseInt(last_li.childNodes[0].dataset.listkey) + 1;
// create the new list tag
const li_element = document.createElement('li');
// create the new input tag for the new advertising code
const input_element = document.createElement('input');
// set the type
input_element.type = "text";
// set the name attribute
input_element.name = "advertising_code[" + new_key + "]";
// set empty value
input_element.value = "";
// add the new key as data attribute
input_element.dataset.listkey = new_key;
// add the new advertising code to the list element
li_element.appendChild(input_element);
// add the list element to the list
document.getElementById('advertising_code_list').appendChild(li_element);
}
发布于 2020-05-06 20:21:13
在PHP打开标签(如 )后在页面顶部添加,并将其称为需要$advertising_code;的地方。
https://wordpress.stackexchange.com/questions/365980
复制相似问题