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.
AND
I have the following templates built into the Theme builder.
Elementor only allows applying templates to
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: /
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.
AND
I have the following templates built into the Theme builder.
Elementor only allows applying templates to
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/
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