This is my new plugin. Categories of your blog are shown on dashboard. By clicking the category you are going to write a post, you will go to a new post page, with the category checked.
When I make a new post, I often forget to check a category. This plugin solves the problem. Before I write a post, the category is already chosen. After I write a post, I simply push the publish button.
<?php class selectcategory { protected $catid ; protected $js ; protected $number = 20; protected $hideempty = 0; protected $order = 'DESC'; protected $unit = 'pt'; protected $orderby = 'cloud'; protected $maxnum = 22; protected $minnum = 8; public function __construct() { add_action( 'admin_head-post-new.php', array(&$this, 'catid_via_get') ); add_action( 'wp_dashboard_setup', array(&$this, 'category_post_dashboard_widget') ); add_action( 'admin_menu', array(&$this, 'myoptionpages_add') ); } public function myoptionpages_add() { add_options_page(__('Select Category to Post', 'selectcategory'), __('Select Category to Post', 'selectcategory'), 'edit_plugins', 'selectcategoryoptions', array(&$this, 'selectcategory_options_page') ); } public function selectcategory_options_page() { ?> <div class="wrap"> <h2><?php _e('Options', 'selectcategory');?></h2> <form method="post" action="options.php"> <?php wp_nonce_field('update-options'); ?> <?php $selectcategory_order = esc_attr(get_option('selectcategory_order', 'count'));?> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="selectcategory_num"><?php _e('Number of Categories', 'selectcategory');?></label></th> <td><input type="text" id="selectcategory_num" name="selectcategory_num" value="<?php esc_html_e(get_option('selectcategory_num', $this->number)); ?>" size="5"></input></td> </tr> <tr valign="top"> <th scope="row"><label for="selectcategory_order"><?php _e('Order of Categories', 'selectcategory');?></label></th> <td><select id="selectcategory_order" name="selectcategory_order"> <option value="name"<?php selected( $selectcategory_order, 'name' ); ?>><?php _e('Name','selectcategory'); ?></option> <option value="count"<?php selected( $selectcategory_order, 'count' ); ?>><?php _e('Count','selectcategory'); ?></option> <option value="none"<?php selected( $selectcategory_order, 'none' ); ?>><?php _e('term_id','selectcategory'); ?></option> <option value="cloud"<?php selected( $selectcategory_order, 'cloud' ); ?>><?php _e('cloud','selectcategory'); ?></option> </select></td> </tr> <tr valign="top"> <th scope="row"><label for="selectcategory_order"><?php _e('Size of Clouds (if you choose cloud)', 'selectcategory');?></label></th> <td>Max: <input type="text" id="maxsize" name="selectcategory_maxnum" value="<?php esc_html_e(get_option('selectcategory_maxnum', $this->maxnum)); ?>" size="5"></input> min: <input type="text" id="minsize" name="selectcategory_minnum" value="<?php esc_html_e(get_option('selectcategory_minnum', $this->minnum)); ?>" size="5"></input></td> </tr> </table> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="selectcategory_num,selectcategory_order,selectcategory_maxnum,selectcategory_minnum" /> <p class="submit"> <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'selectcategory') ?>" /> </p> </form> </div> <?php } public function category_post_dashboard_widget() { wp_add_dashboard_widget('select_category_post', __('Select Category to Post', 'selectcategory'), array(&$this, 'select_category_post')); } public function select_category_post() { $option_orderby = get_option('selectcategory_order', 'count'); if ( $option_orderby == 'name' ) { $this->orderby = 'name'; } elseif ( $option_orderby == 'cloud' ) { $this->orderby = 'name'; } elseif ( $option_orderby == 'count' ) { $this->orderby = 'count'; } elseif ( $option_orderby == 'none' ) { $this->orderby = 'none'; } else { wp_die( 'invalid selectcategory_order' ); } if ( is_numeric( get_option('selectcategory_num', $this->number) ) ) { $this->number = intval( get_option('selectcategory_num', $this->number) ); } else { wp_die( 'invalid selectcategory_num' ); } if ( $option_orderby == 'cloud' ) { print $this->output_cloudlist(); } else { print $this->output_catlist(); } } protected function output_cloudlist() { if ( is_numeric( get_option('selectcategory_maxnum', $this->maxnum) ) ) { $largest = intval( get_option('selectcategory_maxnum', $this->maxnum) ); } else { wp_die( 'invalid selectcategory_maxnum' ); } if ( is_numeric( get_option('selectcategory_minnum', $this->minnum) ) ) { $smallest = intval( get_option('selectcategory_minnum', $this->minnum) ); } else { wp_die( 'invalid selectcategory_minnum' ); } $categories = get_terms('category', array( 'number' => $this->number, 'hide_empty' => $this->hideempty, 'orderby' => 'count', 'order' => $this->order )); foreach ( $categories as $catdata ) { $counts[] = $catdata->count; } $min_count = min( $counts ); $spread = max( $counts ) - $min_count; if ( $spread <= 0 ) { $spread = 1; } $font_spread = $largest - $smallest; if ( $font_spread < 0 ) { $font_spread = 1; } $font_step = $font_spread / $spread; uasort( $categories, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);') ); $output = "<ul class="selectcategory-cloud">n<li>n"; foreach ( $categories as $catdata ) { $cat_id = $catdata->term_id; $catname = wp_specialchars( apply_filters('the_category', $catdata->name) ); $output .= "<a href="" . admin_url('/') . "post-new.php?defaultcatid=". $cat_id ."" title="" . $catname . "" class="selectcategory-" . $cat_id . "" style='font-size: " . ( $smallest + ( ( $catdata->count - $min_count ) * $font_step ) ) . $this->unit . ";'>"; $output .= $catname; $output .= "</a>n"; } $output .= "</li>n</ul>n"; return $output; } protected function output_catlist() { $categories = get_terms('category', array( 'number' => $this->number, 'hide_empty' => $this->hideempty, 'orderby' => $this->orderby, 'order' => $this->order )); $output = "<ul class="selectcategory">n<li>n"; foreach ( $categories as $catdata ) { $cat_id = $catdata->term_id; $catname = wp_specialchars( apply_filters('the_category', $catdata->name) ); $output .= "<a href="" . admin_url('/') . "post-new.php?defaultcatid=". $cat_id ."" title="" . $catname . "" class="selectcategory-" . $cat_id . "">"; $output .= $catname; $output .= "</a>n"; } $output .= "</li>n</ul>n"; return $output; } public function catid_via_get() { if ( current_user_can('edit_posts') && is_numeric( $_GET['defaultcatid'] )){ $this->catid = intval( $_GET['defaultcatid'] ); $this->catidcheck() ; } else { $this->catid = 0; } } protected function catidcheck() { if ( $this->catid ) { add_action( 'admin_print_footer_scripts', array(&$this, 'output_js') ); } } protected function create_js() { $this->js = <<<EOF <script> window.onload= getcatid; function getcatid(){ document.getElementById('in-category- EOF; $this->js .= $this->catid; $this->js .= <<<EOF ').checked = true; } </script> EOF; } public function output_js() { if ( get_cat_name( $this->catid ) ) { $this->create_js(); echo $this->js; } else { wp_die( 'invalid catid' ); } } }
Select Cateogy to Postをインストールさせていただきました。
ダッシュボードにカテゴリ名が表示されたのですが
ここのYouTube映像は縦に綺麗に並んでいますが
私のダッシュボードでは横にずらずらと無造作に並んでしまいます。
さらにデフォルトのカテゴリ名が3倍くらいの大きさで表示されます。
何か設定しないといけないのでしょうか?
marineさん、
最新版だと、管理画面で、スタイルシート設定ができるようにしています。逆にデフォルトの状態だと単に横に並ぶだけです。
スタイルシートで、レイアウトを設定してください。例えば下のように。
#select_category_post a {
display:block;
margin-bottom: 10px;
}
また、文字サイズは、「Size of Clouds」で設定できます。
mizunoさん、早々に回答ありがとうございます。
並び順の設定やフォントサイズの設定もあったのですね。
教えていただいたCSSで綺麗に並びました。
これは便利です!
欲を言えば、ここからカテゴリ指定の投稿一覧画面にも飛んだらもっと楽かも(^^)