• Hi all, figured i’d share something i’ve managed to do and i’ve not seen anyone else yet document, and it is somewhat of a hack, but it does work.

    I thought about writing a blog entry about this, but felt since i spend more time here, and this site is far more active, that it would make more sense to post it here directly…

    I’m sure alot of users want to use QuickPress but still have the ability to select a category for the entries being made. Of course this only covers adding one category, but i decided the option to select one over no selection at all might be of interest to someone.

    Here’s how it’s done.

    Add the following to your theme’s functions.php file:

    function __quickpress_cats() {
    	if(!function_exists('is_admin') || !is_admin()) return;
    	// Parameters for wp_dropdown_categories
    	$args = array(
    		'order' => 'ASC',
    		'hierarchical' => 1,
    		'echo' => 0,
    		'name' => 'post_category[]',
    		'hide_empty' => 0
    	);
    	$select_cats = wp_dropdown_categories( $args );
    	echo '
    	</div>
    	<h4 id="category-label"><label for="post_category">Category</label></h4>
    	<div>
    	'.$select_cats.'
    	</div>
    	<div class="hide-if-no-js" style="margin: 0 0 .5em 5em;padding:8px 10px 5px 5px;">
    	';
    	return;
    }
    if(is_admin() || $query->is_admin) {
    	$here = array( basename($_SERVER['REQUEST_URI']), basename($_SERVER['SCRIPT_FILENAME']) );
    
    	if( ( $here[0] == ('index.php' || 'wp-admin')) && ( $here[1] == 'index.php') ) {
    		add_action('media_buttons','__quickpress_cats');
    	}
    	unset($here);
    }

    The code below the function makes a basic check to see what page you’re on, so as to not hook onto the media-buttons in other places..

    Yes it’s a little hacky, and may not be rocket science, but it does function and give you the ability to choose a category when making QuickPress posts…

    Enjoy!.. ??

Viewing 16 replies (of 16 total)
  • Thread Starter Mark / t31os

    (@t31os_)

    I shall be submitting a trac ticket to ask that some hooks are placed into the QuickPress widget as soon as i get time to run some additional tests.

    Should be a very simple patch, and i would like to be providing a patch with the ticket so it has a better chance of being added into core sooner (if it’s accepted). A few minor problems prevent me from doing that right now, working out how to handle tab-indexes, and deciding whether to add in custom taxonomy support(it would work i believe, been looking at the code involved over the last few days).

    This would mean, rather than replacing the whole callback function with another (ie. what’s been done in the above code), instead hook onto a new action and insert the extra form elements you need. I’ve already tested some hooks in the widget, and it’s definately an easy and workable addition, it’s a just matter of putting together a suitable patch.

    EDIT: Actually why wait, ticket submitted.

    NOTE: Sillybean i believe i know what the problem is with whichever version isn’t working under 3.0, but you’ll need to point out which specific version you’re referring to, so i can correct it, the codex one, or the pastebin one?

    If you’d like to see better control over the QuickPress widget, do your part and vote for the ticket on the ideas section, here.

Viewing 16 replies (of 16 total)
  • The topic ‘Howto: Add category selection to QuickPress’ is closed to new replies.