^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数checked()用法示例

checked( mixed $checked,  mixed $current = true,  bool $echo = true )

Outputs the html checked attribute.


描述

Compares the first two arguments and if identical marks as checked


参数

$checked

(mixed)
(Required)
One of the values to compare

$current

(mixed)
(Optional)
(true) The other value to compare if not just true

Default value: true

$echo

(bool)
(Optional)
Whether to echo or just return the string

Default value: true


返回值

(string) html attribute or empty string


源代码

File: wp-includes/general-template.php

function checked( $checked, $current = true, $echo = true ) {
	return __checked_selected_helper( $checked, $current, $echo, 'checked' );
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

  • wp-includes/general-template.php:
    __checked_selected_helper()

Used By

  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_meta_boxes_preferences()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_list_table_columns_preferences()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_view_mode()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::post_formats_html()
  • wp-signup.php:
    signup_user()
  • wp-admin/includes/network.php:
    network_step1()
  • wp-admin/install.php:
    display_setup_form()
  • wp-admin/includes/user.php:
    use_ssl_preference()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::show_screen_options()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_screen_layout()
  • wp-admin/includes/screen.php:
    meta_box_prefs()
  • wp-admin/includes/misc.php:
    admin_color_scheme_picker()
  • wp-admin/includes/class-walker-category-checklist.php:
    Walker_Category_Checklist::start_el()
  • wp-admin/includes/media.php:
    wp_media_insert_url_form()
  • wp-admin/includes/meta-boxes.php:
    post_comment_status_meta_box()
  • wp-admin/includes/meta-boxes.php:
    link_submit_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_submit_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_format_meta_box()
  • wp-admin/includes/class-walker-nav-menu-edit.php:
    Walker_Nav_Menu_Edit::start_el()
  • wp-admin/includes/file.php:
    request_filesystem_credentials()
  • wp-admin/custom-header.php:
    Custom_Image_Header::step_1()
  • wp-admin/custom-header.php:
    Custom_Image_Header::show_header_selector()
  • wp-admin/custom-background.php:
    Custom_Background::admin_page()
  • wp-includes/widgets/class-wp-widget-tag-cloud.php:
    WP_Widget_Tag_Cloud::form()
  • wp-includes/widgets/class-wp-widget-categories.php:
    WP_Widget_Categories::form()
  • wp-includes/widgets/class-wp-widget-recent-posts.php:
    WP_Widget_Recent_Posts::form()
  • wp-includes/widgets/class-wp-widget-archives.php:
    WP_Widget_Archives::form()
  • wp-includes/widgets/class-wp-widget-links.php:
    WP_Widget_Links::form()
  • wp-includes/widgets.php:
    wp_widget_rss_form()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::render_content()
  • Show 25 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    
    <?php
    
    // Get an array of options from the database.
    $options = get_option( 'slug_option' );
    
    // Get the value of this option.
    $checked = $options['self-destruct'];
    
    // The value to compare with (the value of the checkbox below).
    $current = 1; 
    
    // True by default, just here to make things clear.
    $echo = true;
    
    ?>
    <input name="slug-option[self-destruct]" value="1"
    	<?php checked( $checked, $current, $echo ); ?>/>
    

    Testing the value with if():

    
    <input type='checkbox' name='options[postlink]' value='1'
    	<?php if ( 1 == $options['postlink'] ) echo 'checked="checked"'; ?> />
    

    Using checked() instead:

    
    <input type="checkbox" name="options[postlink]" value="1"
    	<?php checked( $options['postlink'], 1 ); ?> />
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈