我需要帮助来完成这最后一段php代码。我正在尝试创建一个类似于“管理”>“设置”>“讨论”中的管理选项页面,例如用户如何选择化身,但用户选择的不是化身,而是改变主题的样式选项(通过在前端将CSS文件排队)。
我的CSS文件已完成。对于php,到目前为止,我有以下内容:
<?php
// register CSS files ready
function register_custom_styles() {
wp_register_style( \'style1\', plugins_url( \'/css/style1.css\', (__FILE__) ) );
wp_register_style( \'style2\', plugins_url( \'/css/style2.css\', (__FILE__) ) );
wp_register_style( \'style3\', plugins_url( \'/css/style3.css\', (__FILE__) ) );
}
add_action( \'init\', \'register_custom_styles\' );
//create admin sub menu - admin>appearance>styles
add_action(\'admin_menu\', \'my_custom_submenu\');
function my_custom_submenu() {
add_submenu_page( \'themes.php\', \'Styles\', \'Styles\', \'manage_options\', \'styles\', \'my_custom_submenu_page\' );
}
//create admin page for admin>appearance>styles
function my_custom_submenu_page() {
?>
<div>
<h2>Select Style</h2>
<form method="post" action="options.php">
<!--this option to wp_enqueue_style(\'style1\')-->
<label> <input type="radio" name="myoption[radio1]" value="style1" /> <img src="//path-to-style1-img" /> Style1 </label>
<br />
<!--this option to wp_enqueue_style(\'style2\')-->
<label> <input type="radio" name="myoption[radio1]" value="style2" /> <img src="//path-to-style2-img" /> Style2 </label>
<br />
<!--this option to wp_enqueue_style(\'style3\')-->
<label> <input type="radio" name="myoption[radio1]" value="style3" /> <img src="path-to-style3-img" /> Style3 </label>
<br />
<?php submit_button(); ?>
</form>
</div>
<?php
}
如您所见,当用户选择单选输入并单击提交按钮时,我不知道如何将该选项与注册的CSS文件连接起来。https://codex.wordpress.org/Creating_Options_Pages 显示了如何创建选项页面,但没有示例说明如何将CSS文件排入选项队列。
感谢您的帮助。