• Resolved jagp2001

    (@jagp2001)


    Hello, I have my adverts with top categories and child categories.. I want that when I clic on a main category then page that display adverts of this main category also can display sub categories in order to can filter which one sub category I want surf.. how can I do it? , thanks

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, hmm the easiest way to do that would be to just add the “Search By Category” snippet to the [adverts_list] form https://github.com/simpliko/wpadverts-snippets/blob/master/search-by-category/search-by-category.php

    If you would like to display the list of categories in a similar fashion as on the page https://allubu.com/clasificados-categorias/ then this will require some custom programming.

    Below you can find a code to get you started, it will check if the user is currently in the Advert Category (if he is then you need code to get sub categories for $current_category and for displaying them.

    
    add_action( "adverts_sh_list_before", "my_categories" );
    function my_categories( $args ) {
      global $wp_query;
      if( is_tax( 'advert_category' ) ) {
        $current_category = $wp_query->get_queried_object_id();
        // code for getting the sub categories and displaying them here
      }
    }
    
    Thread Starter jagp2001

    (@jagp2001)

    ok thanks, how can I get the code to display sub categories?
    and Do you have an option or addon to display a badge on feautured ads?

    Plugin Author Greg Winiarski

    (@gwin)

    The whole code that will do this can look like this

    
    add_action( "adverts_sh_list_before", "categories_above_adverts_list" );
    function categories_above_adverts_list( $args ) {
      global $wp_query;
      if( is_tax( 'advert_category' ) ) {
        $current_category = $wp_query->get_queried_object_id();
        // code for getting the sub categories and displaying them here
        $columns = "adverts-flexbox-columns-4";
        $show_count = 1;
        $terms = get_terms( 'advert_category', array( 
            'hide_empty' => 0, 
            'parent' => $current_category ,
            'number' => -1
        ) );
        include ADVERTS_PATH . '/templates/categories-top.php';
      }
    }
    
    Thread Starter jagp2001

    (@jagp2001)

    Ok i installed this code but now is working at half.. I mean, when I enter a category it just dispolay one sub categorie icon.. but others are missing.. please check this: https://allubu.com/advert-category/bienes-raices/

    Can you tell me what to do?

    thanks for your help..

    Plugin Author Greg Winiarski

    (@gwin)

    Please try changing the line 'number' => -1 to 'number' => 0.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sub Categories not showed on after clic on top category’ is closed to new replies.