Classifieds Category - Sub categories..... Not sure how to explain what I need! lol..

Right,

On my site with the classifieds categories, I have top level categories, i.e stuff for sale, property, pets, and then sub levels ie

stuff for sale ->
computers
clothes

pets ->
dogs
cats

At the minute, it shows the taxonomies as one long list... How would I go about modifying the taxonomy output to allow for top level taxonomies and sub level taxonomy selection?

Did that make sense?

Cheers guys,

Danny.

  • Philip John
    • DEV MAN’s Apprentice

    What are you using to create that form? Is it custom developed?

    I believe you will need to edit that form in order to pull out the available categories in a structured format that you can then print out in the desired fashion. That's gonna take some custom development...

    Phil

  • Danny
    • Design Lord, Child of Thor

    I am using your classified plugin,

    Do you have a test site with it installed for you to have a look at if you are not familiar with your classifieds plugin?

    Classifieds -> my classifieds -> create new

    What you see in the screenshot is the default output of the page-my-classifieds.php -> create new...

    As for it being the default output.. Hmmm, it is not a user friendly classifieds plugin if it does not show the differentiation of parent/child categories when a user is posting a classified ad nor is it good that users can post in top level categories..

  • Danny
    • Design Lord, Child of Thor

    Hey Andrey,

    I am working on a quick fix and it is really bugging me.. I have implemented this code into the page-my-classifieds.php

    <script type="text/javascript">
    $(function(){
    $('#main_cat').change(function(){
    var $mainCat=$('#main_cat').val();
    // call ajax
    $("#terms").empty();
    $.ajax({
    url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
    type:'POST',
    data:'action=my_special_ajax_call&main_catid=' + $mainCat,
    success:function(results){
    //  alert(results);
    $("#terms").removeAttr("disabled");
    $("#terms").append(results);
    }
    });
    }
    );
    });
    </script>
    <?php
    wp_dropdown_categories('show_count=0&hierarchical=1&depth=1&hide_empty=0&show_option_none=Select Topic&name=main_cat&taxonomy=classifieds_categories');
    ?>

    and this code in my functions.php

    function implement_ajax() {
    if(isset($_POST['main_catid']))
    {
    $categories=  get_categories('taxonomy=classifieds_categories&child_of='.$_POST['main_catid'].'&hide_empty=0');
    foreach ($categories as $term) {
    $option .= '<option value="'.$term->slug;
    if (is_array($_POST['terms'][$taxonomy_name] ) && in_array( $term->slug, $_POST['terms'][$taxonomy_name] ) );
    $option .= '">';
    $option .= $term->name;;
    $option .= '</option>';
    }
    echo '<option value="-1" selected="selected">Select Category</option>'.$option;
    die();
    } // end if
    }
    add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
    add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.

    And it has given me a menu which can be seen here http://norwich.my-city-social.co.uk/classifieds/my-classifieds/ (you will have to click on the create marketplace ad..)

    The problem is, when you submit the create marketplace ad form, it is not passing the categories back through..

    Do you know how I can fix this? I am sure it is something simple..

    Thanks,

    Danny..

  • Danny
    • Design Lord, Child of Thor

    WOOP!!! lol Got it working..

    For those who want a quick fix...

    Replacement in page-my-classifieds.php

    replace line

    271 to 287 with this:

    <script type="text/javascript">
    $(function(){
    $('#main_cat').change(function(){
    var $mainCat=$('#main_cat').val();
    
    // call ajax
    $("#terms").empty();
    $.ajax({
    url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
    type:'POST',
    data:'action=my_special_ajax_call&main_catid=' + $mainCat,
    success:function(results){
    //  alert(results);
    $("#terms").removeAttr("disabled");
    $("#terms").append(results);
    }
    });
    }
    );
    });
    </script>
    <?php
    wp_dropdown_categories('show_count=0&hierarchical=1&depth=1&hide_empty=0&show_option_none=Select Main Category&name=main_cat&taxonomy=classifieds_categories');
    ?>
    <select name="terms[classifieds_categories]" id="terms" disabled="disabled" ></select>

    then in functions.php (in your theme root),

    put in:

    function implement_ajax() {
    if(isset($_POST['main_catid']))
    {
    $terms=  get_categories('taxonomy=classifieds_categories&child_of='.$_POST['main_catid'].'&hide_empty=0');
    foreach ($terms as $term) {
    $option .= '<option value="'.$term->slug;
    if (is_array($_POST['terms'][$taxonomy_name] ) && in_array( $term->slug, $_POST['terms'][$taxonomy_name] ) );
    $option .= '" selected="selected">';
    $option .= $term->name;
    $option .= '</option>';
    }
    echo '<option value="-1" selected="selected">Select Sub-Category</option>'.$option;
    die();
    } // end if
    }
    add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
    add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');//for users that are not logged in.

    The perfect quick fix until Andrey sorts it out :slight_smile:

    Regards,

    Danny

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.