function wpjam_admin_pagenavi($total_count, $number_per_page = 50) { $current_page = isset($_GET['paged']) ? $_GET['paged'] : 1; $base_url = remove_query_arg(array('paged'), wpjam_get_current_page_url()); $total_pages = ceil($total_count / $number_per_page); $first_page_url = $base_url . '&paged=1'; $last_page_url = $base_url . '&paged=' . $total_pages; if ($current_page > 1 && $current_page < $total_pages) { $prev_page = $current_page - 1; $prev_page_url = $base_url . '&paged=' . $prev_page; $next_page = $current_page + 1; $next_page_url = $base_url . '&paged=' . $next_page; } elseif ($current_page == 1) { $prev_page_url = '#'; $first_page_url = '#'; if ($total_pages > 1) { $next_page = $current_page + 1; $next_page_url = $base_url . '&paged=' . $next_page; } else { $next_page_url = '#'; } } elseif ($current_page == $total_pages) { $prev_page = $current_page - 1; $prev_page_url = $base_url . '&paged=' . $prev_page; $next_page_url = '#'; $last_page_url = '#'; } ?> <div class="tablenav-pages"> <span class="displaying-num"><?php /*每页 <?php echo $number_per_page;?> 个项目,*/ ?> 共 <?php echo $total_count; ?> 个项目</span> <span class="pagination-links"> <a class="first-page <?php if ($current_page == 1) { echo 'disabled'; } ?> " title="前往第一页" href="<?php echo $first_page_url; ?> ">«</a> <a class="prev-page <?php if ($current_page == 1) { echo 'disabled'; } ?> " title="前往上一页" href="<?php echo $prev_page_url; ?> ">‹</a> <span class="paging-input">第 <?php echo $current_page; ?> 页,共 <span class="total-pages"><?php echo $total_pages; ?> </span> 页</span> <a class="next-page <?php if ($current_page == $total_pages) { echo 'disabled'; } ?> " title="前往下一页" href="<?php echo $next_page_url; ?> ">›</a> <a class="last-page <?php if ($current_page == $total_pages) { echo 'disabled'; } ?> " title="前往最后一页" href="<?php echo $last_page_url; ?> ">»</a> </span> </div> <br class="clear"> <?php }
function wpjam_option_page($option_name, $args = array()) { if (!$option_name) { return; } $wpjam_setting = wpjam_get_option_setting($option_name); if (!$wpjam_setting) { return; } extract($wpjam_setting); extract(wp_parse_args($args, array('page_title' => '', 'page_type' => 'tab'))); if (!$sections) { return; } if (count($sections) == 1) { $page_type = 'default'; } do_action($option_name . '_option_page'); if (is_multisite() && is_network_admin()) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { // 如果是 network 就自己保存到数据库 $value = wpjam_option_field_validate($_POST[$option_name], $option_name); update_site_option($option_name, $value); wpjam_admin_add_error(__('Options saved.')); wpjam_admin_errors(); } echo '<form action="' . add_query_arg(array('settings-updated' => 'true'), wpjam_get_current_page_url()) . '" method="POST">'; } else { echo '<form action="options.php" method="POST">'; } $wpjam_option = wpjam_get_option($option_name); global $section_summary; $section_summary = array(); foreach ($sections as $section_id => $section) { $section_title = isset($section['title']) ? $section['title'] : ''; $section_callback = isset($section['callback']) ? $section['callback'] : ''; if (isset($section['summary'])) { $section_summary[$section_id] = $section['summary']; $section_callback = 'wpjam_option_section_callback'; } add_settings_section($section_id, $section_title, $section_callback, $option_page); if (!$section['fields']) { continue; } foreach ($section['fields'] as $key => $field) { $field['key'] = $key; $field['name'] = $option_name . '[' . $key . ']'; $field_title = '<label for="' . $key . '">' . $field['title'] . '</label>'; if ($field['type'] == 'fieldset') { foreach ($field['fields'] as $sub_key => $sub_field) { $field['fields'][$sub_key]['value'] = isset($sub_field['value']) ? $sub_field['value'] : (isset($wpjam_option[$sub_key]) ? $wpjam_option[$sub_key] : ''); $field['fields'][$sub_key]['name'] = $option_name . '[' . $sub_key . ']'; } } else { $field['value'] = isset($field['value']) ? $field['value'] : (isset($wpjam_option[$key]) ? $wpjam_option[$key] : ''); } add_settings_field($key, $field_title, $field_callback, $option_page, $section_id, $field); } } settings_fields($option_group); if ($page_type == 'tab') { wpjam_do_settings_sections($option_page); if (!empty($_GET['settings-updated'])) { $wpjam_option = wpjam_get_option($option_name); echo '<input type="hidden" name="' . $option_name . '[current_tab]" id="current_tab" value="' . $wpjam_option['current_tab'] . '" />'; } else { echo '<input type="hidden" name="' . $option_name . '[current_tab]" id="current_tab" value="" />'; } } else { echo $page_title ? preg_match("/<[^<]+>/", $page_title) ? $page_title : '<h2>' . $page_title . '</h2>' : ''; // 如 $page_title 里面有 <h2> <h3> 标签,就不再加入 <h2> <h3> 标签了。 settings_errors(); do_settings_sections($option_page); } submit_button(); echo '</form>'; }