0

I have a few templates built with Elementor Theme Builder. However, the option to display them on nested archives is quite limited. Here's my case

I have a custom taxonomy (tags) called Locations. Which is then further nested as listings are added. It gets the address and breaks it down to Region, City, and Locality, and inserts then set the terms. No dramas here. This is how it looks.

enter image description here

AND

I have the following templates built into the Theme builder.

  1. Region Template (Applies to Waikato, also all other regions)
  2. City Template (Applies to Hamilton, Also all other other cities)
  3. Locality Template (Applies to Frankton 3204, all to all other localities)
  4. Service Template (Applies to Coffee shop in Frankton, also to all other services)

Elementor only allows applying templates to

  1. All locations (this includes the children's terms)
  2. Direct children of Locations
  3. Any child of Location

enter image description here

However in my case, I want to apply 4 different templates to the parent (region), child (city), grandchild (locality), and great-grandchild (service in the locality).

Elementor allows one to register custom conditions in Theme builder, however, I am not able to. Welp!

add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) { 
class Subcategory_Archive extends ElementorPro\Modules\ThemeBuilder\Conditions\Taxonomy {
    private $taxonomy;

    public function get_name() {
        return 'child_of_' . $this->taxonomy->name;
    }

    public function get_label() {
        return sprintf( __( 'Direct Child %s Of', 'elementor-pro' ), $this->taxonomy->labels->singular_name );
    }

    public function __construct( $data ) {
        parent::__construct( $data );

        $this->taxonomy = $data['object'];
    }

    public function is_term() {
        $taxonomy = $this->taxonomy->name;
        $current = get_queried_object();
        return ( $current && isset( $current->taxonomy ) && $taxonomy === $current->taxonomy );
    }

    public function check( $args ) {
        $id = (int) $args['id'];
        /**
         * @var \WP_Term $current
         */
        $current = get_queried_object();
        if ( ! $this->is_term() || 0 === $current->parent ) {
            return false;
        }

        while ( $current->parent > 0 ) {
            if ( $id === $current->parent ) {
                return true;
            }
            $current = get_term_by( 'id', $current->parent, $current->taxonomy );
        }

        return $id === $current->parent;
    }
}
$taxonomy = get_term('location');

$conditions_manager->get_condition( 'listing' )->register_sub_condition( new Subcategory_Archive([ 'object' => $taxonomy ]) );
}, 100 );

I need help to register custom conditions for the archive pages to display those taxononmies.

NOTE: there's option of individually selecting each term and applying the template. However, I have over 2500 listing categories (i.e Coffee shop) and thousands of localities and cities. I can manage regions because there are only 16 regions in NZ.

Elementor Docs: https://developers.elementor.com/docs/theme-conditions/

1 Answer 1

0

did you get any further with that issue? I'm facing same right now

Update

Everyone having trouble solving this, have a look @ elementors github issue. The magic lays in the check function

https://github.com/elementor/elementor/issues/8155

1
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
    – cjbj
    Commented Apr 26, 2023 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.