ds3422222222 2013-05-01 01:55
浏览 23
已采纳

需要有人向我展示如何修改我的代码以创建多个复选框

I am trying to figure our how to modify this code so that it creates a checkbox for each entry in the meta_key.

It is a meta box that will be used on the menu page.

The meta_key has multiple entries that I want to appear in the check list of the meta box. I would also like for the URL inputbox to contain the same meta value that was checked as well. If someone could point me in the right direction I would really appreciate it.

Here is the code I used to echo a list of the meta values from the key. I need to use it to create a checkbox for each value.

<?php echo esc_attr( get_post_meta($post->ID, 'newtheme_section_id', true) ); ?>

Here is the code I am using to create the meta box.

if ( !class_exists('JMO_Custom_Nav')) {
    class JMO_Custom_Nav {
        public function add_nav_menu_meta_boxes() {
            add_meta_box(
                'wl_login_nav_link',
                __('WishList Login'),
                array( $this, 'nav_menu_link'),
                'nav-menus',
                'side',
                'low'
            );
        }

        public function nav_menu_link() {?>
            <div id="posttype-wl-login" class="posttypediv">
                <div id="tabs-panel-wishlist-login" class="tabs-panel tabs-panel-active">
                    <ul id ="wishlist-login-checklist" class="categorychecklist form-no-clear">
                        <li>
                            <label class="menu-item-title">
                                <input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1"> This is the code for checkbox
                            </label>
                            <input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="custom">
                            <input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="Login">
                            <input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value="<?php echo esc_attr( get_post_meta($post->ID, 'newtheme_section_id', true) ); ?>
                            <input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" value="wl-login-pop">
                        </li>
                    </ul>
                </div>
                <p class="button-controls">
                    <span class="list-controls">
                        <a href="/wordpress/wp-admin/nav-menus.php?page-tab=all&amp;selectall=1#posttype-page" class="select-all">Select All</a>
                    </span>
                    <span class="add-to-menu">
                        <input type="submit" class="button-secondary submit-add-to-menu right" value="Add to Menu" name="add-post-type-menu-item" id="submit-posttype-wl-login">
                        <span class="spinner"></span>
                    </span>
                </p>
            </div>
        <?php }
    }
}

$custom_nav = new JMO_Custom_Nav;

add_action('admin_init', array($custom_nav, 'add_nav_menu_meta_boxes'))
  • 写回答

1条回答 默认 最新

  • dpntq48842 2013-05-01 02:04
    关注

    You are telling get_post_meta to bring a single value with the third parameter, try with something like:

    $sections = get_post_meta($post->ID, 'newtheme_section_id', false);
    
    foreach( $sections as $section ) {
      // do something with $section
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用