Remove comma from category list

This topic contains 10 replies, has 3 voices, and was last updated by  Andrea Piaggesi 7 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #387501

    Andrea Piaggesi
    Expired Member
    Post count: 42

    Hi,
    is there a way to remove commas and the last “and” from the category list?

    Thanks!
    Andrea

    #387574

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    I asked to the developers to check if there is a hook and to let us know,

    Thanks

    #387582

    Giri
    Expired Member
    Post count: 3155
    
    
    function geodir_cf_taxonomy_modified($html,$location,$cf,$p=''){
    
        // check we have the post value
        if(is_int($p)){$post = geodir_get_post_info($p);}
        else{ global $post;}
    
        if(!is_array($cf) && $cf!=''){
            $cf = geodir_get_field_infoby('htmlvar_name', $cf, $post->post_type);
            if(!$cf){return NULL;}
        }
    
        $html_var = $cf['htmlvar_name'];
    
        // Check if there is a location specific filter.
        if(has_filter("geodir_custom_field_output_taxonomy_loc_{$location}")){
            /**
             * Filter the taxonomy html by location.
             *
             * @param string $html The html to filter.
             * @param array $cf The custom field array.
             * @since 1.6.6
             */
            $html = apply_filters("geodir_custom_field_output_taxonomy_loc_{$location}",$html,$cf);
        }
    
        // Check if there is a custom field specific filter.
        if(has_filter("geodir_custom_field_output_taxonomy_var_{$html_var}")){
            /**
             * Filter the taxonomy html by individual custom field.
             *
             * @param string $html The html to filter.
             * @param string $location The location to output the html.
             * @param array $cf The custom field array.
             * @since 1.6.6
             */
            $html = apply_filters("geodir_custom_field_output_taxonomy_var_{$html_var}",$html,$location,$cf);
        }
    
        // Check if there is a custom field key specific filter.
        if(has_filter("geodir_custom_field_output_taxonomy_key_{$cf['field_type_key']}")){
            /**
             * Filter the taxonomy html by field type key.
             *
             * @param string $html The html to filter.
             * @param string $location The location to output the html.
             * @param array $cf The custom field array.
             * @since 1.6.6
             */
            $html = apply_filters("geodir_custom_field_output_taxonomy_key_{$cf['field_type_key']}",$html,$location,$cf);
        }
    
        // If not html then we run the standard output.
        if(empty($html)){
    
            if ($html_var == $post->post_type . 'category' && !empty($post->{$html_var})) {
                $post_taxonomy = $post->post_type . 'category';
                $field_value = $post->{$html_var};
                $links = array();
                $terms = array();
                $termsOrdered = array();
                if (!is_array($field_value)) {
                    $field_value = explode(",", trim($field_value, ","));
                }
    
                $field_value = array_unique($field_value);
    
                if (!empty($field_value)) {
                    foreach ($field_value as $term) {
                        $term = trim($term);
    
                        if ($term != '') {
                            $term = get_term_by('id', $term, $html_var);
                            if (is_object($term)) {
                                $links[] = "<a href='" . esc_attr(get_term_link($term, $post_taxonomy)) . "'>" . $term->name . "</a>";
                                $terms[] = $term;
                            }
                        }
                    }
                    if (!empty($links)) {
                        // order alphabetically
                        asort($links);
                        foreach (array_keys($links) as $key) {
                            $termsOrdered[$key] = $terms[$key];
                        }
                        $terms = $termsOrdered;
                    }
                }
                $html_value = !empty($links) && !empty($terms) ? $links : '';
    
                if (is_array($html_value)) {
                    $html_value = implode(' ', $html_value);
                }
    
                if ($html_value != '') {
                    $field_icon = geodir_field_icon_proccess($cf);
                    if (strpos($field_icon, 'http') !== false) {
                        $field_icon_af = '';
                    } else if ($field_icon == '') {
                        $field_icon_af = '';
                    } else {
                        $field_icon_af = $field_icon;
                        $field_icon = '';
                    }
    
                    $html = '<div class="geodir_more_info ' . $cf['css_class'] . ' ' . $html_var . '" style="clear:both;"><span class="geodir-i-taxonomy geodir-i-category" style="' . $field_icon . '">' . $field_icon_af;
                    $html .= (trim($cf['site_title'])) ? __($cf['site_title'], 'geodirectory') . ': ' : '';
                    $html .= '</span> ' . $html_value . '</div>';
                }
            }
    
        }
    
        return $html;
    }
    remove_filter('geodir_custom_field_output_taxonomy','geodir_cf_taxonomy',10);
    add_filter('geodir_custom_field_output_taxonomy','geodir_cf_taxonomy_modified',10,3);
    #387604

    Andrea Piaggesi
    Expired Member
    Post count: 42

    Hi,
    sorry but I’ve just added the code to my functions.php and the commas are still there.

    Thanks!
    Andrea

    #387605

    Paolo
    Site Admin
    Post count: 31211

    hi,

    please provide a link and admin credentials and we will have a look.

    Thanks

    #387606

    Andrea Piaggesi
    Expired Member
    Post count: 42
    This reply has been marked as private.
    #387607

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    I alerted Giri, he’ll let you know asap.

    Thanks for your patience,

    #387671

    Giri
    Expired Member
    Post count: 3155

    Hi there,

    The code I given earlier is for the categories you see in sidebar. For the top part use this code.

    
    
    add_filter('geodir_details_taxonomies_output', 'geodir_details_taxonomies_output_commaless', 10, 4);
    function geodir_details_taxonomies_output_commaless($taxonomies, $post_type,$listing_label, $listing_label_uc) {
        if (!geodir_is_page('detail')) {
            return $taxonomies;
        }
        $post_taxonomy = $post_type . 'category';
        if (isset($taxonomies[$post_taxonomy])) {
            $taxonomies[$post_taxonomy] = str_replace("</a> and <a", "</a><a", $taxonomies[$post_taxonomy]);
            $taxonomies[$post_taxonomy] = str_replace("</a>, and <a", "</a><a", $taxonomies[$post_taxonomy]);
            $taxonomies[$post_taxonomy] = str_replace("</a>, <a", "</a><a", $taxonomies[$post_taxonomy]);
        }
    
        return $taxonomies;
    }
    #387766

    Andrea Piaggesi
    Expired Member
    Post count: 42

    Thank you very much, that worked!

    Please can you point me to the correct hooks for editing the Grid View Listings content.
    I would like to add some informations to each listing of the Grid View, for example some xprofile informations of the BuddyPress author profile.

    Thank you very much.
    Andrea

    #387768

    Paolo
    Site Admin
    Post count: 31211

    Hi,

    To add anything to listings in widget and listings pages you have the action:

    do_action('geodir_after_listing_post_excerpt', $post);

    Please open new topics for any new question, this is resolved and we’re going off topic now.

    Thanks

    #387848

    Andrea Piaggesi
    Expired Member
    Post count: 42

    Okkk thank you very much for the help.
    Andrea

Viewing 11 posts - 1 through 11 (of 11 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount