对不起,我的代码格式。请任何人帮助我编辑此代码格式。
“在主题的功能文件中使用下面的代码。之后,它将在“管理”>“外观”>“主页”中的图像1下方显示一个选项。从那里可以上载图像。”
function register_my_logo(){ register_setting(\'logo_options_group\',\'logo_options_group\'); }add_action( \'admin_init\', \'register_my_logo\' );
function add_logo_page_to_settings() {
add_theme_page(\'Theme Logo\',
\'Homepage below image 1 ->\',
\'manage_options\',
\'edit_logo\',
\'logo_edit_page\'); }
add_action(\'admin_menu\', \'add_logo_page_to_settings\');
function logo_edit_page() {?>
<div class="section panel">
<h1>Custom homepage images and url change</h1>
<form method="post" enctype="multipart/form-data" action="options.php">
<?php settings_fields(\'logo_options_group\'); // this will come later
do_settings_sections(\'logo_options_group\'); // and this too...
?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e(\'Save Changes\') ?>" />
</p>
</form>
<?php }function add_logo_options_to_page(){add_settings_section(
\'custom_logo\',
\'Customize the site homepage image:\',
\'custom_logo_fields\',
\'logo_options_group\' );
$args=array(); // pass arguments to add_settings_array to use in fields
add_settings_field( \'logo_url\', "image", \'logo_upload_url\' , \'logo_options_group\', \'custom_logo\', $args );
add_settings_field(\'title\',\'Title\',\'logo_upload_url\',\'logo_options_group\',\'logo_options_group\',$args);
add_settings_field(
\'cus_url\', //id
\'Custom URL\', //title
\'logo_upload_url\', //callback
\'logo_options_group\', //page
\'logo_options_group\', //section
$args
);}
add_action(\'admin_init\',\'add_logo_options_to_page\');
function logo_upload_url($args){$options=get_option(\'logo_options_group\') ;?>
<br><label for="upload_image"><input id="url" type="text" size="36" value="<?php echo $options[\'url\']; ?>" name="logo_options_group[url]" /><input id="upload_logo_button" type="button" value="Upload Image" /><br />Enter an URL or upload an image for the banner.</label>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(\'#upload_logo_button\').click(function() {
formfield = jQuery(\'#url\').attr(\'name\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
return false;});
window.send_to_editor = function(html) {
imgurl = jQuery(\'img\',html).attr(\'src\');
jQuery(\'#url\').val(imgurl);
tb_remove(); }});</script>
<?php if($options[\'url\']){
echo "<br>This is your current logo: <br><img src=\'". $options[\'url\'] ."\' style=\'padding:20px;\' />";
echo "<br>To use it in a theme copy this: <blockquote>". htmlspecialchars("<?php do_shortcode(\'[sitelogo]\'); ?>") ."</blockquote><br> To use it in a post or page copy this code:<blockquote>[sitelogo]</blockquote>"; } ?>
<br>This is your current Title: <br><input type="text" id="title" name="logo_options_group[title]" value="<?php echo $options[\'title\']; ?>" /> <br>This is your current URL: <br><input type="text" id="cus_url" name="logo_options_group[cus_url]" value="<?php echo $options[\'cus_url\']; ?>" />
<?php}function custom_logo_fields(){**// you can add stuff here if you like...**}
function my_admin_scripts() {wp_enqueue_script(\'media-upload\');wp_enqueue_script(\'thickbox\');}
function my_admin_styles() { wp_enqueue_style(\'thickbox\'); }
if (isset($_GET[\'page\']) && $_GET[\'page\'] == \'edit_logo\') {add_action(\'admin_print_scripts\', \'my_admin_scripts\'); add_action(\'admin_print_styles\', \'my_admin_styles\'); }
function get_site_logo(){$option=get_option("logo_options_group"); if($option[\'url\']){echo "<img src=\'". $option[\'url\'] ."\' />";} else {echo "Sorry, No logo selected";}} add_shortcode(\'sitelogo\', \'get_site_logo\');
Then to display that image in your template use this code.
<?php $option=get_option(\'logo_options_group\') ; ?>
<div><a href="<?php echo $option[\'cus_url\']; ?>"><?php do_shortcode(\'[sitelogo]\'); ?><?php echo $option[\'title\']; ?></a></div>