Categories and Viewing Listing Defaults

This topic contains 7 replies, has 4 voices, and was last updated by  Guust 9 years, 7 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #45638

    Christy Robinson
    Free User
    Post count: 20

    I have a few questions:

    1) How do I control the order of the categories? My categories are the days of the week, and I want them in order.

    2) How do I control how the listings look after searching? Right now a lot of information is there and I really just want the picture and restaurant name.

    3) How do I control the default view of the listing? I created an information field titled happy hour details and that is what I want to show on default.

    You can view my site here: happyhour-girl.com

    Thank you in advance.

    *I apologize, I originally posted this under general discussion.

    #45656

    Guust
    Moderator
    Post count: 29970

    1. Hello, the widget shows the categories in order of most “popular”, meaning most listings within the categories. It cannot be changed.

    2. GD > desdign > search
    https://wpgeodirectory.com/docs/core-design/#search

    3. Where do you want the custom field to show by default? I guess on the listings, location and search pages?
    Tick “show on listing page” in the custom field settings:
    https://wpgeodirectory.com/docs/core-place-settings/#common

    #46703

    Christy Robinson
    Free User
    Post count: 20

    I am still having trouble understanding the response to my question. How can I sort the categories on the listing pages? Example: https://happyhour-girl.com/happy-hours/houston/sunday/anejo/

    Please see how the listing looks really weird with it showing the place categories in this odd order.

    Also, how do I get the Happy Hour Details to be the first tab on the listing page instead of More Info?

    #46717

    Guust
    Moderator
    Post count: 29970

    I thought you were asking about the order of categories in the popular category widget.

    Now that you linked to a listing, I understand your question.
    I think for the purpose of ordering them on the detail page, you should be able to change the ID of the categories, I think they are ordered by ID, but it might break your database.
    So I’ll ask the others, don’t change anything yet.

    This blog post should help you re-order the tabs:
    https://wpgeodirectory.com/re-order-tabs-in-a-listing-detail-page/

    #46726

    Christy Robinson
    Free User
    Post count: 20

    I actually made sure to add the categories in the order I wanted them, so if it were ordering them by the ID it would be perfect. It is actually putting the categories in alphabetical order. I really need to fix this so please help me.

    #46808

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Christy,

    I am not sure how good you are with code so let us know if you need more help but adding this to your theme functions.php should do it (not tested).
    Basically we order them A-Z, i have removed that part in this code

    Thanks,

    Stiofan

    
    
    
    remove_action('geodir_details_taxonomies', 'geodir_action_details_taxonomies', 10);
    add_action('geodir_details_taxonomies', 'my_geodir_action_details_taxonomies', 10);
    /**
     * Output link to the posts categories and tags.
     *
     * @global bool $preview True of on a preview page. False if not.
     * @global object $post The current post object.
     * @since 1.0.0
     * @package GeoDirectory
     */
    function my_geodir_action_details_taxonomies()
    {
        global $preview, $post;?>
        <p class="geodir_post_taxomomies clearfix">
        <?php
        $taxonomies = array();
    
        $is_backend_preview = (is_single() && !empty($_REQUEST['post_type']) && !empty($_REQUEST['preview']) && !empty($_REQUEST['p'])) && is_super_admin() ? true : false; // skip if preview from backend
    
        if ($preview && !$is_backend_preview) {
            $post_type = $post->listing_type;
            $post_taxonomy = $post_type . 'category';
            $post->$post_taxonomy = $post->post_category[$post_taxonomy];
        } else {
            $post_type = $post->post_type;
            $post_taxonomy = $post_type . 'category';
        }
    //{	
        $post_type_info = get_post_type_object($post_type);
        $listing_label = $post_type_info->labels->singular_name;
    
        if (!empty($post->post_tags)) {
    
            if (taxonomy_exists($post_type . '_tags')):
                $links = array();
                $terms = array();
                // to limit post tags
                $post_tags = trim($post->post_tags, ",");
                $post_id = isset($post->ID) ? $post->ID : '';
                /**
                 * Filter the post tags.
                 *
                 * Allows you to filter the post tags output on the details page of a post.
                 *
                 * @since 1.0.0
                 * @param string $post_tags A comma seperated list of tags.
                 * @param int $post_id The current post id.
                 */
                $post_tags = apply_filters('geodir_action_details_post_tags', $post_tags, $post_id);
    
                $post->post_tags = $post_tags;
                $post_tags = explode(",", trim($post->post_tags, ","));
    
                foreach ($post_tags as $post_term) {
    
                    // fix slug creation order for tags & location
                    $post_term = trim($post_term);
    
                    $priority_location = false;
                    if ($insert_term = term_exists($post_term, $post_type . '_tags')) {
                        $term = get_term_by('name', $post_term, $post_type . '_tags');
                    } else {
                        $post_country = isset($_REQUEST['post_country']) && $_REQUEST['post_country'] != '' ? $_REQUEST['post_country'] : NULL;
                        $post_region = isset($_REQUEST['post_region']) && $_REQUEST['post_region'] != '' ? $_REQUEST['post_region'] : NULL;
                        $post_city = isset($_REQUEST['post_city']) && $_REQUEST['post_city'] != '' ? $_REQUEST['post_city'] : NULL;
                        $match_country = $post_country && sanitize_title($post_term) == sanitize_title($post_country) ? true : false;
                        $match_region = $post_region && sanitize_title($post_term) == sanitize_title($post_region) ? true : false;
                        $match_city = $post_city && sanitize_title($post_term) == sanitize_title($post_city) ? true : false;
                        if ($match_country || $match_region || $match_city) {
                            $priority_location = true;
                            $term = get_term_by('name', $post_term, $post_type . '_tags');
                        } else {
                            $insert_term = wp_insert_term($post_term, $post_type . '_tags');
                            $term = get_term_by('name', $post_term, $post_type . '_tags');
                        }
                    }
    
                    if (!is_wp_error($term) && is_object($term)) {
    
                        // fix tag link on detail page
                        if ($priority_location) {
                            $links[] = "<a href=''>$post_term</a>";
                        } else {
                            $links[] = "<a href='" . esc_attr(get_term_link($term->term_id, $term->taxonomy)) . "'>$term->name</a>";
                        }
                        $terms[] = $term;
                    }
                    //
                }
                if (!isset($listing_label)) {
                    $listing_label = '';
                }
                $taxonomies[$post_type . '_tags'] = wp_sprintf('%s: %l', ucwords($listing_label . ' ' . __('Tags', GEODIRECTORY_TEXTDOMAIN)), $links, (object)$terms);
            endif;
    
        }
    
        if (!empty($post->$post_taxonomy)) {
            $links = array();
            $terms = array();
            $termsOrdered = array();
            if (!is_array($post->$post_taxonomy)) {
                $post_term = explode(",", trim($post->$post_taxonomy, ","));
            } else {
                $post_term = $post->$post_taxonomy;
            }
    
            $post_term = array_unique($post_term);
            if (!empty($post_term)) {
                foreach ($post_term as $post_term) {
                    $post_term = trim($post_term);
    
                    if ($post_term != ''):
                        $term = get_term_by('id', $post_term, $post_taxonomy);
                        if (is_object($term)) {
                            $links[] = "<a href='" . esc_attr(get_term_link($term, $post_taxonomy)) . "'>$term->name</a>";
                            $terms[] = $term;
                        }
                    endif;
                }
                // order alphabetically
                /*asort($links);
                foreach (array_keys($links) as $key) {
                    $termsOrdered[$key] = $terms[$key];
                }
                $terms = $termsOrdered;
    */
    
            }
    
            if (!isset($listing_label)) {
                $listing_label = '';
            }
            $taxonomies[$post_taxonomy] = wp_sprintf('%s: %l', ucwords($listing_label . ' ' . __('Category', GEODIRECTORY_TEXTDOMAIN)), $links, (object)$terms);
    
        }
    
        if (isset($taxonomies[$post_taxonomy])) {
            echo '<span class="geodir-category">' . $taxonomies[$post_taxonomy] . '</span>';
        }
    
        if (isset($taxonomies[$post_type . '_tags']))
            echo '<span class="geodir-tags">' . $taxonomies[$post_type . '_tags'] . '</span>';
    
        ?>
        </p><?php
    }
    #49159

    scott voelker
    Free User
    Post count: 4

    We are trying to sort the order of the categories alphabetically. This cannot be that difficult, but no where can I find how to do this. If you look at the attached photo, where it shows “Resource Center Categories”, the categories are listed in reverse alphabetical order. I don’t know why, as they were not added in this order, not looked at in popularity in this order, etc… (This Resource Center Categories” was the Popular Categories (we just changed the name).

    If we can’t change the order of what was popular categories, we need to have the categories of the various firms shown here some how (we don’t care about the popularity of the places/companies – we just want the categories listed alphabetically.

    Thank you,
    Scott

    #49197

    Guust
    Moderator
    Post count: 29970

    Scott, the code above shows you how to re-arrange the categories.

    By default, the categories are listed with the highest number of listings in the category first (that is why it is called popular categories widget).

    If there is only one listing in each category, it will list it by order of the ID in the database (or reverse order, not real sure).

Viewing 8 posts - 1 through 8 (of 8 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