WordPress.org

Ready to get started?Download WordPress

Forums

Dropdown Category Selection for Publishing Posts in P2 theme v.1.1.3 (27 posts)

  1. acrofilo
    Member
    Posted 4 years ago #

    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.

  2. Thet Twe
    Member
    Posted 4 years ago #

    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.

  3. Nobble
    Member
    Posted 4 years ago #

    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.

  4. aritzbm
    Member
    Posted 4 years ago #

    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.

  5. Nobble
    Member
    Posted 4 years ago #

    I'll see what I can do

  6. aritzbm
    Member
    Posted 4 years ago #

    thank you very much. id really appreciate it.

  7. Nobble
    Member
    Posted 4 years ago #

    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()

  8. aritzbm
    Member
    Posted 4 years ago #

    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.

  9. Nobble
    Member
    Posted 4 years ago #

    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.

  10. aritzbm
    Member
    Posted 4 years ago #

    Thank you very much for all your help Nobble.

  11. Andre_ger
    Member
    Posted 4 years ago #

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

  12. williamle8300
    Member
    Posted 4 years ago #

    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!

  13. pushpinderbagga
    Member
    Posted 4 years ago #

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

  14. densscessario
    Member
    Posted 4 years ago #

    Can we use that in WordPress.com blog?

  15. nathanmckenna
    Member
    Posted 3 years ago #

    @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.

  16. nathanmckenna
    Member
    Posted 3 years ago #

    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.

  17. Nobble
    Member
    Posted 3 years ago #

    @Nathan,

    I hadn't tested the code with version 1.1.5 yet but I may upload a p2 modified version for it next week if I can create the time. Without seeing your code it is hard to say what's not working.

  18. diniscorreia
    Member
    Posted 3 years ago #

    Hi all,

    I was looking for a similar solution, but instead of having the category on the post-form, I would need a dropdown category selection in every published post (I'm using P2 as a collaborative tool and categories will be used like 'status' types - "follow up", "completed", etc).

    Is this possible to achieve?

    Thanks in advance!

  19. Nobble
    Member
    Posted 3 years ago #

    @Nathan I've uploaded a copy with drop categories for 1.1.5, it seems to be working fine on my end. The code I had stated earlier still works, it's just the line numbers have changed a bit (the code that is being replaced has not). I put the download on sendspace.

    @dini
    possible yes, do you want a user to click on a button after selecting a category or are you wanting the change to happen dynamically? Not sure about the latter but think it can be done with ajax. Front-end-editor plugin by Scribu is a great starting point.

  20. cembleton2
    Member
    Posted 3 years ago #

    Does anyone know how to do exactly what the original poster described for version 1.1.6.2? This is precisely what I'm trying to figure out--i.e., I need for users to be able to choose from a drop-down categories list the category that best fits their post.

    Thank you, thank you, THANK YOU to anyone who can explain how these changes can be made in version 1.1.6.2! :D

  21. cembleton2
    Member
    Posted 3 years ago #

    Now that I read it again, I should probably clarify my question a bit: Is there a way to modify the P2 theme so that, when a visitor is looking at the front end of the website (not the Dashboard), types their message into the box at the top of the screen, and hits the "Post It" button, there will also be an option for them to select a category for their post from a drop-down list?

  22. Nobble
    Member
    Posted 3 years ago #

    fyi, I just checked p2 v1.1.7 and above code still works for me.

  23. jittipat
    Member
    Posted 3 years ago #

    Thanks in advance!
    Touchwebdesign

  24. cembleton2
    Member
    Posted 3 years ago #

    Hi Nobble,

    Thank you for pointing out the release of v1.1.7! I didn't realize they'd recently upgraded. I have a quick question concerning your instructions: I'm finding everything you're referencing except the first step ("In p2.js go to line 217 which should show: ....") are you referring to js.php? I ask because I couldn't find the line 217 language you're describing in js.php and feel that I might be looking in the wrong place.

    Thanks again,

    Cindy

  25. cembleton2
    Member
    Posted 3 years ago #

    Sorry for the false alarm... for whatever reason, my website folder contained 2 copies of p2.js and both were in an odd location, which confused things a bit. I got rid of the doppelganger and just followed the instructions, and they worked like a charm. Thank you so much!

  26. cembleton2
    Member
    Posted 3 years ago #

    Nobble, thank you again for your help with the code. Mine works great! I have a question for everyone (in case anyone has had to do this); does anyone know of a workable code that would produce the same exact function, except with subcategories as well? So for example, if I have a dessert website, and a user wants to find cookies in the West Village NYC, they can select the category "West Village"; then under that, choose "Cookies"?

  27. jdblundell
    Member
    Posted 3 years ago #

    This is exactly what I'm trying to do but @Noble's solution seems to fail with P2 1.2.1.

    I'm pretty sure I had it working with an earlier version of P2 on my test machine but now that I've upgraded it doesn't want to play well with the new version :-(.

    Here's my site (currently in the final stages of development - will go live once this is fixed again :-)):

    http://www.simplechurchipedia.com

    I can select the category from the drop down, but the posts only display in either status, post, link, quote etc. categories.

    Is there something missing in 1.2.1 that would force WordPress to give the drop down option priority over the buttons (status, post, link) up top? Or even allow WordPress to tag the posts with multiple categories?

Topic Closed

This topic has been closed to new replies.

About this Topic