首先,按如下方式注册设置:
function my_awesome_register_fields_for_additional_settings(){
register_setting(\'reading\', \'my_awesome_pagelink_for_frontend_button\');
add_settings_field(\'my_awesome_pagelink_for_frontend_button\', \'<label for="my_awesome_pagelink_for_frontend_button">The Frontend Button shall link to this page:</label>\' , \'my_awesome_pagelink_for_frontend_button_html\', \'reading\');
}
add_filter(\'admin_init\', \'my_awesome_register_fields_for_additional_settings\');
然后,为设置字段定义回调:
function my_awesome_pagelink_for_frontend_button_html(){
$option = (int)get_option(\'my_awesome_pagelink_for_frontend_button\',0);
wp_dropdown_pages(array(
\'selected\' => $option,
\'name\' => \'my_awesome_pagelink_for_frontend_button\',
\'show_option_none\' => \'Please Choose\',
\'option_none_value\' => 0,
));
}
wp\\u dropdown\\u pages函数使用页面ID作为值,因此您已经设置好了。
你现在需要做的就是像这样回应前端的按钮:
if($buttonlink = (int)get_option(\'my_awesome_pagelink_for_frontend_button\',0)){
?><a href="<?php echo get_permalink($buttonlink); ?>" class="button"><?php echo get_the_title($buttonlink); ?></a><?php
}
快乐编码,Kuchenundkakao
编辑:语言。