'image', //singular name of the listed records 'plural' => 'images', //plural name of the listed records 'ajax' => false //does this table support ajax? ) ); } function column_default($item, $column_name){ switch($column_name){ case 'name': case 'post_title': case 'post_date': return $item[$column_name]; default: return print_r($item,true); //Show the whole array for troubleshooting purposes } } function column_post_title($item){ //Build row actions $actions = array( 'edit' => sprintf('Edit',$_REQUEST['page'],'edit',$item['ID']) ); //Return the title contents return sprintf('%1$s (id:%2$s)', /*$1%s*/ $item['post_title'], /*$2%s*/ $item['ID'] ); } function column_tx($item) { $tx = sprintf('Save in all',$item['ID']); return $tx; } function column_date($item) { $date = sprintf('%s',$item['post_date']); return $date; } function column_qty($item) { $qty = sprintf('%s',$item['attached']); return $qty; } function get_columns(){ $columns = array( 'post_title' => 'Title', 'name' => 'Category', 'date' => 'Date', 'qty' => 'Attached images', 'tx' => 'New title' ); return $columns; } function get_sortable_columns() { $sortable_columns = array( 'post_title' => array('post_title',true), //true means its already sorted 'name' => array('name',false), 'date' => array('post_date',false) ); return $sortable_columns; } function prepare_items() { $per_page = 10; // qty of images to show $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); function traigo($tipo) { global $wpdb; $querystr = "SELECT p.ID, p.post_title, p.post_date, wp_terms.name, (SELECT COUNT(pp.ID) FROM wp_posts pp WHERE pp.post_type = 'attachment' AND pp.post_parent = p.ID) as attached FROM wp_posts p LEFT JOIN wp_term_relationships ON (p.ID =wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) LEFT JOIN wp_terms ON(wp_terms.term_id =wp_term_taxonomy.term_id) WHERE p.post_status='publish' "; if ($tipo == 'post') { $querystr = $querystr." AND $wpdb->term_taxonomy.taxonomy = 'category'"; } $data = $wpdb->get_results( $querystr, ARRAY_A ); return $data; } $tipo = "post"; $data = traigo($tipo); function usort_reorder($a,$b){ $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order return ($order==='asc') ? $result : -$result; //Send final sort direction to usort } usort($data, 'usort_reorder'); $current_page = $this->get_pagenum(); $total_items = count($data); $data = array_slice($data,(($current_page-1)*$per_page),$per_page); $this->items = $data; $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items/$per_page) ) ); } } function tt_add_menu_items(){ $icon = plugin_dir_url( __FILE__ ); $icon = $icon.'/pictures.png'; add_menu_page('Attached images title editor', 'Images title editor', 'activate_plugins', 'tt_list_test', 'tt_render_list_page', $icon); } add_action('admin_menu', 'tt_add_menu_items'); function tt_render_list_page(){ $css = plugin_dir_url( __FILE__ ).'style.css' ; wp_enqueue_style( "mass editor", $css ); $testListTable = new TT_List_Table(); $testListTable->prepare_items(); ?>
This plugin is here to help you edit images at once!