我正常用的主题设置的拓展页面,看效果图:

代码:https://gist.github.com/yao3060/5028434

mythemeoption

<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
add_action('admin_menu', 'my_theme_options_menu');

function my_theme_options_menu() {
    add_action('admin_print_scripts', 'my_options_admin_scripts');
    add_action('admin_print_styles', 'my_options__admin_styles');
    add_theme_page('My Plugin Theme', 'My Theme Options', 'administrator', 'my-theme-options', 'my_theme_options_function');
    add_action('admin_init', 'register_mysettings');
    add_action('admin_init', 'my_theme_icl_register_string');
}

function register_mysettings() {
    //register our settings
    register_setting('my_theme_options', 'myoption');
}

function my_options_admin_scripts() {
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_enqueue_script('my-upload');
}

function my_options__admin_styles() {
    wp_enqueue_style('thickbox');
}

function my_theme_options_function() {
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $my_theme_options = get_option('myoption'); 
    ?>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" /> 
  <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>  
    <div class="wrap"> 
        <?php screen_icon(); ?>
        <h2>My Theme Options</h2>
        <form method="post" id="my_theme_options" action="options.php"> 
            <?php
            settings_fields('my_theme_options');
            ?>

            <table class="form-table" id="my_theme_options">
                <tr>
                    <th scope="row">Logo</th>
                    <td><input type="text" id="my_logo" class="image_upload"  name="myoption[logo][url]" value="<?php echo $my_theme_options[logo][url]; ?>" ></td>
                    <td>
					<?php 
					if($my_theme_options[logo][id]){
						echo wp_get_attachment_image( $my_theme_options[logo][id], array(100,100));
					}else{
						echo '<img src="'.admin_url().'/images/wordpress-logo.png"><br>';
					}
					?>
					<input type="text" name="myoption[logo][id]" value="<?php echo $my_theme_options[logo][id]; ?>"></td>
                </tr>
                <tr>
                    <th scope="row">Favicon</th>
                    <td><input type="text" id="my_favicon"  class="image_upload"  name="myoption[favicon][url]" value="<?php echo $my_theme_options[favicon][url]; ?>" ></td>
                    <td>
					<?php 
					if($my_theme_options[favicon][id]){
						echo wp_get_attachment_image( $my_theme_options[favicon][id], array(100,100));
					}else{
						echo '<img src="'.admin_url().'/images/wordpress-logo.png"><br>';
					}
					?>
					<input type="text" name="myoption[favicon][id]" value="<?php echo $my_theme_options[favicon][id]; ?>">
					</td>
                </tr>
                <tr>
                    <th scope="row">Home Background</th>
                    <td>
						<input type="text" id="my_homebg"  class="image_upload"  name="myoption[homebg][url]" value="<?php echo $my_theme_options[homebg][url]; ?>" ><br>
						<input type="text" id="my_homebg_pos" name="myoption[homebg][pos]" value="<?php echo $my_theme_options[homebg][pos]; ?>" placeholder="Background Position( 0px 0px)" ><br>
						<input type="text" id="my_homebg_repeat" name="myoption[homebg][repeat]" value="<?php echo $my_theme_options[homebg][repeat]; ?>" placeholder="Background Repeat" ><br>
						<input type="text" id="my_homebg_height" name="myoption[homebg][h]" value="<?php echo $my_theme_options[homebg][h]; ?>" placeholder="Height" >
					</td>
                    <td>
					<?php 
					if($my_theme_options[homebg][id]){
						echo wp_get_attachment_image( $my_theme_options[homebg][id], array(100,100));
					}else{
						echo '<img src="'.admin_url().'/images/wordpress-logo.png"><br>';
					}
					?>
					<input type="text" name="myoption[homebg][id]" value="<?php echo $my_theme_options[homebg][id]; ?>">
					</td>
                </tr>
                <tr>
                    <th scope="row">Contact page</th>
                    <td>
<select name="myoption[contact_id]"> 
 <option value=""><?php echo esc_attr( __( 'Select page' ) ); ?></option> 
 <?php 
  $pages = get_pages(); 
  foreach ( $pages as $page ) {
	if($my_theme_options[contact_id] == $page->ID ){ $select = 'selected="selected"'; }else{ $select = ""; }
  	echo '<option value="'. $page->ID .'" '. $select .'>'.$page->post_title.'</option>';
  }
 ?>
</select>			</td>
                    <td></td>
                </tr>
                <tr>
                    <th scope="row">
					<h2>Categroies</h2>
					<p>Press Ctrl, Mutil select the categories</p>
					</th>
                    <td>
<ol id="selectable">
<?php
$categoryIDs = explode('&', $my_theme_options[categroies][id]);

$categories=get_categories();
foreach($categories as $category) { 
	if(in_array($category->term_id, $categoryIDs)) {
		$term_class = "ui-state-default ui-selected";
	}else{
		$term_class = "ui-state-default";
	}
	echo '<li  class="'.$term_class.'" rel="'.( $category->term_id ).'">'.$category->name.'</li>';
}
?> 
</ol>
					</td>
                    <td><input type="text" id="select_result" name="myoption[categroies][id]" value="<?php echo $my_theme_options[categroies][id]; ?>"></td>
                </tr>
				<tr>
                    <th scope="row">
					 Custom Post Type 

					</th>
                    <td>
<select name="myoption[post_type]"> 	 
<?php 
$post_types=get_post_types(array(  'public'   => true,  '_builtin' => false)); 
foreach ($post_types as $post_type ) {
	if('attachment' != $post_type){
		if($my_theme_options[post_type] == $post_type ){ $thisselect = 'selected="selected"'; }else{ $thisselect = ""; }
		$post_type_object = get_post_type_object($post_type);
		echo '<option value="'. $post_type .'" '. $thisselect .'>'.$post_type_object->labels->singular_name.'</option>';
	}
}
?>
</select>

					</td>
				</tr>

				<tr>
                    <th scope="row">
					 Custom Post Type 2

					</th>
                    <td>
<select name="myoption[post_type2]"> 	 
<?php 

foreach ($post_types as $post_type2 ) {
	if('attachment' != $post_type2){
		if($my_theme_options[post_type2] == $post_type2 ){ $thisselect2 = 'selected="selected"'; }else{ $thisselect2 = ""; }
		$post_type_object = get_post_type_object($post_type2);
		echo '<option value="'. $post_type .'" '. $thisselect2 .'>'.$post_type_object->labels->singular_name.'</option>';
	}
}
?>
</select>

					</td>
				</tr>

                <tr>
                    <th scope="row">Share Lable</th>
                    <td><input type="text" id="my_share_lable"  class="my_text_field"  name="myoption[_share][str]" value="<?php echo $my_theme_options[_share][str]; ?>" ></td>
                    <td><input type="checkbox" name="myoption[_share][t]" <?php if ($my_theme_options[_share][t] == 1) echo "checked"; ?> value="1"> register to WPML? </td>
                </tr>

                <tr>
                    <th scope="row">Share Code</th>
                    <td><textarea rows="3" cols="20" class="my_share_code"  name="myoption[share_code]"><?php echo $my_theme_options[share_code]; ?></textarea></td>
                    <td></td>
                </tr>

                <tr>
                    <th scope="row">Analysis Code</th>
                    <td><textarea rows="3" cols="20" class="my_analysis_code"  name="myoption[analysis]"><?php echo $my_theme_options[analysis]; ?></textarea></td>
                    <td></td>
                </tr>

                <tr>
                    <th scope="row" colspan="3"> <?php submit_button(); ?> </th>
                </tr> 
                <tr>
                    <th scope="row" colspan="3"><pre> <?php print_r($my_theme_options); ?> </pre></th>
                </tr> 

            </table>
        </form>
    </div>
  <style> 
 #selectable .ui-selecting { background: #FECA40; }
  #selectable .ui-selected { background: #F39814; color: white; }
  #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
  #selectable li { margin: 3px; padding: 0.4em;  height: 18px; }
 textarea { width: 100%; height: 200px;}
.form-table td, .form-table th{vertical-align: top;border: 1px solid #e2e2e2; } #my_theme_options input.image_upload { width: 100% } #my_theme_options img { max-width: 100px;}</style>	  
    <script>
        var $ =jQuery.noConflict();

        jQuery(document).ready(function($) {
			$( "#selectable" ).selectable({
			  stop: function() {
				var list_tag_selected = [];
				var result = $( "#select-result" ).empty();
				$( ".ui-selected", this ).each(function() { 
				  list_tag_selected.push($(this).attr("rel"));
				  $('#select_result').val(list_tag_selected.join("&"));
				});
			  }
			});

            $('#my_theme_options input.image_upload').live("click",function(){
                formfield = $(this).attr('name');
                field_id = $(this).attr('id');
                preview_img = $(this).parent().next().find('img');
				preview_id  = $(this).parent().next().find('input');
                //alert(field_id);
                tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
                return false;
            });
            window.send_to_editor = function(html) {

				imgelement = $('img',html);
				//alert(imgelement);
				$classes = imgelement.attr('class');
				imgurl = imgelement.attr('src');
				$image_id = $classes.replace(/(.*?)wp-image-/, '');
                $("#"+field_id).val(imgurl);
                preview_img.attr("src",imgurl); 
              	preview_id.val($image_id);
                tb_remove();
            }
        });
    </script>
    <?php
}

function my_theme_icl_register_string() {
    if (function_exists('icl_register_string')) {
        $my_theme_options = get_option('myoption');
        foreach ($my_theme_options as $key => $mt_option) {
            if (is_array($mt_option) && $mt_option[t] == 1) {
                icl_register_string('My theme options', $key, $mt_option[str]);
            }
        }
    }
}
?>

581 thoughts on “My WordPress Theme Options

  1. Cheap Cars

    We are a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable info to work on. You have done a formidable job and our entire community will be grateful to you.

  2. Casino Online

    Awesome write-up. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time.

  3. togel sgp

    Hiya, I am really glad I’ve found this info. Today bloggers publish just about gossip and web stuff and this is really irritating. A good website with interesting content, that’s what I need. Thanks for making this web site, and I will be visiting again. Do you do newsletters by email?

  4. Civil Law

    Nice post. I was checking continuously this blog and I am impressed! Very helpful info specifically the last part 🙂 I care for such information much. I was looking for this particular information for a very long time. Thank you and best of luck.

  5. Civil Law

    Excellent post. I was checking continuously this blog and I’m impressed! Very helpful information specifically the last part 🙂 I care for such information a lot. I was seeking this certain information for a very long time. Thank you and good luck.

  6. judi online

    Hello there. I found your web site by the use of Google whilst searching for a related subject, your web site got here up. It seems good. I have bookmarked it in my google bookmarks to come back then.

  7. Lawsuit

    I wish to voice my love for your kind-heartedness supporting individuals who really want assistance with this concern. Your special commitment to passing the solution all-around appeared to be astonishingly useful and has surely permitted women much like me to get to their targets. The insightful help and advice means much to me and extremely more to my office colleagues. Many thanks; from everyone of us.

  8. Automobile De Germany

    Thank you so much for providing individuals with an extraordinarily remarkable opportunity to read in detail from here. It is always so kind and also stuffed with a great time for me personally and my office acquaintances to search the blog on the least three times in a week to find out the newest secrets you will have. And indeed, I’m just actually fascinated with your gorgeous guidelines served by you. Selected 2 tips in this post are in fact the most impressive I have had.

  9. camera

    Hey, you used to write excellent, but the last several posts have been kinda boring¡K I miss your great writings. Past few posts are just a bit out of track! come on!

  10. Home Decor

    Awesome post. I’m a normal visitor of your site and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.

  11. judi online

    Hiya, I am really glad I have found this info. Nowadays bloggers publish only about gossip and internet stuff and this is really frustrating. A good blog with exciting content, that is what I need. Thank you for making this web-site, and I will be visiting again. Do you do newsletters by email?

  12. Auction Cars

    Hello there, just became alert to your blog through Google, and found that it is really informative. I am going to watch out for brussels. I’ll appreciate if you continue this in future. Many people will be benefited from your writing. Cheers!

  13. Business Ideas

    Great remarkable issues here. I am very satisfied to look your post. Thank you a lot and i’m taking a look ahead to contact you. Will you kindly drop me a mail?

  14. Streaming knowing brother

    Thanks for sharing excellent informations. Your site is so cool. I’m impressed by the details that you¡¦ve on this blog. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found just the information I already searched all over the place and just couldn’t come across. What a perfect web-site.

  15. taruhan bola

    Hey there. I found your website by way of Google whilst searching for a similar matter, your web site came up. It seems great. I have bookmarked it in my google bookmarks to visit then.

  16. mebel jepara

    Awesome write-up. I’m a normal visitor of your web site and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time.

  17. Ayam Jago Bangkok

    Hiya, I’m really glad I have found this info. Today bloggers publish just about gossip and web stuff and this is really irritating. A good site with exciting content, this is what I need. Thanks for making this site, and I will be visiting again. Do you do newsletters by email?

  18. Belajar Forex

    Hey there. I discovered your web site by means of Google whilst searching for a related topic, your site got here up. It seems to be great. I have bookmarked it in my google bookmarks to come back then.

  19. happy birthday card

    Hello there. I discovered your blog via Google at the same time as searching for a related topic, your site got here up. It looks good. I’ve bookmarked it in my google bookmarks to visit then.

  20. PilihDana.com

    Awesome write-up. I am a normal visitor of your site and appreciate you taking the time to maintain the excellent site. I will be a frequent visitor for a really long time.

  21. qqjurnal

    Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish only about gossip and internet stuff and this is really frustrating. A good site with interesting content, that is what I need. Thank you for making this website, and I will be visiting again. Do you do newsletters by email?

  22. www.thealexandria.net

    Hey there. I discovered your web site by the use of Google even as searching for a related topic, your web site came up. It appears good. I have bookmarked it in my google bookmarks to come back then.

  23. Download Anime Live Action Subtitle Indonesia

    Hiya, I am really glad I’ve found this info. Nowadays bloggers publish just about gossip and web stuff and this is really irritating. A good website with interesting content, that’s what I need. Thank you for making this site, and I’ll be visiting again. Do you do newsletters by email?

  24. Art Painting

    I would like to thank you for the efforts you have put in writing this blog. I’m hoping the same high-grade web site post from you in the upcoming also. Actually your creative writing skills has encouraged me to get my own website now. Actually the blogging is spreading its wings rapidly. Your write up is a great example of it.

  25. pusat grosir mukena

    Hello there. I discovered your blog by the use of Google even as searching for a similar topic, your site got here up. It seems to be great. I’ve bookmarked it in my google bookmarks to come back then.

  26. pakaian wangi

    Hiya, I am really glad I have found this information. Nowadays bloggers publish only about gossip and internet stuff and this is really annoying. A good web site with interesting content, this is what I need. Thank you for making this web-site, and I will be visiting again. Do you do newsletters by email?

  27. situs bandar judi online

    Hiya, I’m really glad I’ve found this information. Nowadays bloggers publish just about gossip and internet stuff and this is really irritating. A good blog with exciting content, that is what I need. Thanks for making this website, and I will be visiting again. Do you do newsletters by email?

  28. Financial News

    It¡¦s really a cool and helpful piece of information. I¡¦m glad that you simply shared this helpful info with us. Please stay us up to date like this. Thank you for sharing.

  29. Income

    Valuable information. Lucky me I discovered your website unintentionally, and I’m stunned why this accident did not happened in advance! I bookmarked it.

  30. dominoqq

    Awesome write-up. I’m a normal visitor of your website and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a really long time.

  31. Opportunity

    Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more clear from this post. I’m very glad to see such fantastic information being shared freely out there.

  32. dewa poker

    Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish just about gossip and internet stuff and this is really frustrating. A good site with interesting content, this is what I need. Thank you for making this website, and I’ll be visiting again. Do you do newsletters by email?

  33. Money

    Great post. I was checking constantly this blog and I am impressed! Extremely useful information particularly the last part 🙂 I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck.

  34. id pro poker

    Hiya, I’m really glad I’ve found this information. Today bloggers publish just about gossip and web stuff and this is actually frustrating. A good site with interesting content, that is what I need. Thanks for making this website, and I will be visiting again. Do you do newsletters by email?

  35. Small Business

    My brother suggested I might like this web site. He was totally right. This post truly made my day. You cann’t imagine simply how much time I had spent for this info! Thanks!

  36. situs poker online terpopuler

    Hiya, I am really glad I’ve found this info. Today bloggers publish just about gossip and net stuff and this is actually annoying. A good web site with interesting content, that’s what I need. Thanks for making this website, and I’ll be visiting again. Do you do newsletters by email?

  37. Profitability

    I would like to thank you for the efforts you have put in writing this blog. I’m hoping the same high-grade site post from you in the upcoming also. Actually your creative writing abilities has encouraged me to get my own website now. Actually the blogging is spreading its wings rapidly. Your write up is a great example of it.

  38. The Business

    Heya i am for the first time here. I found this board and I find It really useful & it helped me out a lot. I hope to give something back and aid others like you helped me.

  39. The Business

    I simply wanted to appreciate you once again. I do not know what I could possibly have made to happen in the absence of the entire tips and hints revealed by you regarding such subject. It was an absolute depressing setting in my circumstances, however , coming across this specialised style you solved the issue made me to cry for joy. I am grateful for the assistance as well as expect you are aware of a great job you happen to be getting into instructing people today through the use of your web blog. More than likely you haven’t met all of us.

  40. Art Painting

    Excellent weblog right here! Additionally your website lots up fast! What web host are you the use of? Can I get your associate hyperlink on your host? I wish my website loaded up as fast as yours lol

发表评论