/** * @return number Current page number */ public static function cur_page() { if (!self::$cur_page) { if (isset($_GET[self::VAR_NAME]) && intval($_GET[self::VAR_NAME])) { self::$cur_page = $_GET[self::VAR_NAME]; } else { self::$cur_page = 1; } } return self::$cur_page; }
/** * Outputs posts table rows * * @param array $posts - Array of posts from get_sorted or get_unsorted functions * @param string $post_type - Post Type name * @param string $tax_name - Taxonomy name (slug) * */ protected static function list_posts($posts, $post_type = '', $tax_name = '') { if (!$posts) { echo '<tr><td colspan="5">' . __('No records found', self::ID) . '</td></tr>' . PHP_EOL; return false; } $settings = self::user_settings_load(); if (!$settings['rows_per_page']) { $rpp = 20; } else { $rpp = $settings['rows_per_page']; } $tr_count = q2w3_post_order_table_paging::cur_page() * $rpp - $rpp + 1; $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); foreach ($posts as $post) { if ($tr_count % 2 > 0) { $alter = "class='alternate'"; } else { $alter = ''; } echo "<tr {$alter}>" . PHP_EOL; if (isset($post['post_rank']) && $post['post_rank']) { $pos = $post['post_rank']; } else { $pos = $tr_count; } echo '<td style="text-align: center">' . $pos . '</td>' . PHP_EOL; echo '<td style="text-align: center">' . $post['ID'] . '</td>' . PHP_EOL; echo '<td style="text-align: center">' . mysql2date($datetime_format, $post['post_date']) . '</td>' . PHP_EOL; echo '<td><a href="post.php?post=' . $post['ID'] . '&action=edit" target="_blank">' . $post['post_title'] . '</a></td>' . PHP_EOL; echo '<td style="text-align: center">'; echo '<input name="posts[' . $post['ID'] . '][new_pos]" type="text" size="6" maxlength="6">'; if ($post_type) { echo '<input type="hidden" name="posts[' . $post['ID'] . '][post_type]" value="' . $post_type . '" />'; } elseif ($tax_name) { echo '<input type="hidden" name="posts[' . $post['ID'] . '][tax_name]" value="' . $tax_name . '" />'; } if (isset($post['id']) && $post['id']) { // We are in sorted posts table echo '<input type="hidden" name="posts[' . $post['ID'] . '][id]" value="' . $post['id'] . '" />'; echo '<input type="hidden" name="posts[' . $post['ID'] . '][pos]" value="' . $post['post_rank'] . '" />'; } echo '</td>' . PHP_EOL; echo '</tr>' . PHP_EOL; $tr_count++; $post_ids[] = $post['ID']; } return $post_ids; }
</th> <th scope="col" style="width: 100px"><?php _e('Change position', self::ID); ?> </th> </tr> </thead> <tbody id="asc-list"> <?php self::list_posts(self::get_unsorted_posts($term_id, $tax_name, $post_type, $exclude_ids), $post_type, $tax_name); ?> </tbody> </table> <div class="tablenav"> <?php echo q2w3_post_order_table_paging::controls($total_posts, $rpp); ?> </div> <input type="submit" value="<?php _e('Update Unsorted', self::ID); ?> " class="button-primary" /> </form> <?php function q2w3_post_order_term_name($term_id, $tax_name) { $terms_array = q2w3_post_order_term_array($term_id, $tax_name); return implode(' • ', $terms_array); } function q2w3_post_order_term_array($term_id, $tax_name)