WordPress.org

Support

Support » Plugins and Hacks » Dropdown Category Selection for Publishing Posts in P2 theme v.1.1.3

Dropdown Category Selection for Publishing Posts in P2 theme v.1.1.3

  • Hi everybody,

    I’ve read every single topic related to this issue, and I have tried every single possible solution but to no avail. It seems to me anything working doesn’t apply to the latest version of P2. I have even tried old solutions for older versions of P2 (such as the one provided by omarvelous, but this one didn’t work the ajax and replies didn’t work).

    I need for users to be able to choose from a dropdown categories list the one that fits best with their post. I’ve added the dropdown successfully but I’m not able to get it to record the category. I’ve tried hacking the ajax and functions files, as suggested in other related topics, but still no success.

    I would greatly appreciate it if anyone could tell me how to get P2 1.1.3 to record post categories when selected from a dropdown list.

    Thank you very much, in advance. I’ve been going crazy with this for many days now.

Viewing 15 replies - 1 through 15 (of 26 total)
  • I updated the download link for you at this thread. Please try it

    http://wordpress.org/support/topic/309164?replies=3

    I don’t know whether it will compatible with the latest version v 1.1.3, since i haven’t try yet. That one sure works for 1.0.4.

    You try to replace the files inside the folder that I uploaded. If it doesn’t work, I will take a look for 1.1.3 and will update it.

    that will no doubt not work Thet, the code is significantly different in v1.1+

    a hack for drop down category selection would need changes in 4 files, assuming your using categories other than the 4 (status update, blogpost, quote etc) provided with v1.1+

    the files are p2.js, functions.php, post-form.php and ajax.php

    I might provide a solution in februari when I have more time but if anyone before me has already cracked it, I hope they share it here.

    Does anyone have a solution for this? Or has anyone made it work? acrofilo, did it work your you? Nobble have you been able to make it work?
    thank you very much.

    I’ll see what I can do

    thank you very much. id really appreciate it.

    Here goes:

    in p2.js go to line 217 which should show:

    var args = {action: 'new_post', _ajax_post:nonce, posttext: posttext, tags: tags, post_cat: post_cat, post_title: post_title, post_citation: post_citation };

    replace this with:

    var drop_cat = $('#drop_cat').val();
    var args = {action: 'new_post', _ajax_post:nonce, posttext: posttext, tags: tags, post_cat: post_cat, drop_cat: drop_cat, post_title: post_title, post_citation: post_citation };

    in ajax.php, find around line 155:

    $accepted_post_cats = apply_filters( 'p2_accepted_post_cats', array( 'post', 'quote', 'status', 'link' ) );
    		$post_cat = ( in_array( $_POST['post_cat'], $accepted_post_cats ) ) ? $_POST['post_cat'] : 'post';

    make a backup, or comment these lines out and replace with:

    $drop_cat= $_POST['drop_cat'];
    $post_cat = $_POST['post_cat'];
    if ($drop_cat) { $post_cat = $drop_cat;} //if a category was selected from the drop down menu, this will become the category.

    then we need to add the actual dropdown menu, in post-form.php add this before line 78 (before the form closes)

    <select name="drop_cat" id="drop_cat">
     <option value=""><?php echo attribute_escape(__('Select Category')); ?></option>
     <?php
      $categories=  get_categories();
      foreach ($categories as $cat) {
      	$option = '<option value="'.$cat->category_nicename.'">';
    	$option .= $cat->cat_name;
    	$option .= ' ('.$cat->category_count.')';
    	$option .= '</option>';
    	echo $option;
      }
     ?>
    </select>

    In case you want to exclude categories you can control what categories are displayed by passing parameters to get_categories()

    It works great! Thank you so much. You have resolved an issue many people have been trying to solve!
    I will bother you with one more question: How can I force users to choose a category? so that if they dont choose one the post doesnt go into “post” “status” “link” etc…

    Once again, thank you very much.

    If you need to force a category choice from the drop down box:

    add this to post-forms.php:

    <label class="cat-error" for="dropcat" id="dropcat_error"></label>

    I put it directly after the drop down selection.
    note that the class ‘cat-error’ defines the display through css for the warning message.

    in p2.js you’ll need to rearrange one line we added before:

    $drop_cat= $_POST['drop_cat'];

    and place it earlier inside the function, with a few new lines. Find the line that states:

    if(jQuery('.no-posts')) jQuery('.no-posts').hide();

    and add this straight after that line:

    var drop_cat = $('#drop_cat').val(); // assigns the drop category value
    
    		if ("" == drop_cat) { // checks the drop category value, if empty, will pass a message
    			$("label#dropcat_error").text('Please select a category').show().focus();
    			return false;
    		}

    This should work but keep in mind this kind of defeats the purpose of the post types/tab functionality p2 uses.

    Thank you very much for all your help Nobble.

    Hi Nobble, thank you very much for this solution, this helps me a lot!

    Nobble, I guess I have a similar question that Acrofolio had.

    How do you implement custom fields into the p2 theme? jonobr1 tackled it here for p2 ver1, however the new p2 differs alot in the code and jonobr1’s solution doesn’t work in this iteration of p2.

    Appreciate any help, or if you can point me in the right direction. Thanks!

    worked like a gem, thanks a ton to Nobble. Cheers man!

    Can we use that in WordPress.com blog?

    @nobble

    Hi Nobble, seems like you’re the person to ask about this. I want exactly what acrofilo has achieved here.
    I followed your instructions carefully but when loading my blog I got an error in a line of the functions.php, stopping the blog from loading. I couldn’t log in so had to reinstall the theme.

    – I’m using the P2 version 1.1.5
    – I didn’t make any changes to the functions.php because I just followed your instructions, I guess I should make changes but have no idea how?

    Any help greatly appreciated.

    ok, update on that. I got it half working. After selecting a category and hitting “post” it seems to go through fine only it doesn’t put the post into the selected category, it stays in the category of whatever was highlight, ie “Status Update”.

    Any help greatly appreciated.

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘Dropdown Category Selection for Publishing Posts in P2 theme v.1.1.3’ is closed to new replies.