admin管理员组文章数量:1293693
I modified my posts widget in Elementor with a custom skin in order to show multiple badges with following code:
/* MULTIPLE BADGES ON POST */
/* --- */
add_action( 'elementor/widget/posts/skins_init', function( $widget ) {
class cards_multi_badge_skin extends \ElementorPro\Modules\Posts\Skins\Skin_Cards {
protected function render_badge() {
$taxonomy = $this->get_instance_value( 'badge_taxonomy' );
if ( empty( $taxonomy ) ) {
return;
}
$terms = get_the_terms( get_the_ID(), $taxonomy );
if ( ! is_array( $terms ) ) {
return;
}
?><div class="elementor-post__badges"><?php
foreach( $terms as $term ) : ?>
<div class="elementor-post__badge"><?php echo $term->name; ?></div>
<?php endforeach; ?>
</div>
<?php
}
public function get_id() {
return 'cards_multi_badge';
}
public function get_title() {
return __( 'Cards Multi Badge', 'elementor-pro' );
}
}
// register the skin to the posts widget
$widget->add_skin( new cards_multi_badge_skin( $widget ) );
} );
This leads to following result:
Now, I'm trying the same for the archive posts widget in Elementor with following code:
/* MULTIPLE BADGES ON ARCHIVE POST */
/* --- */
add_action( 'elementor/widget/archive-posts/skins_init', function( $widget ) {
class cards_multi_badge_skin extends \ElementorPro\Modules\Archive_Posts\Skins\Skin_Cards {
protected function render_badge() {
$taxonomy = $this->get_instance_value( 'badge_taxonomy' );
if ( empty( $taxonomy ) ) {
return;
}
$terms = get_the_terms( get_the_ID(), $taxonomy );
if ( ! is_array( $terms ) ) {
return;
}
?><div class="elementor-post__badges"><?php
foreach( $terms as $term ) : ?>
<div class="elementor-post__badge"><?php echo $term->name; ?></div>
<?php endforeach; ?>
</div>
<?php
}
public function get_id() {
return 'cards_multi_badge';
}
public function get_title() {
return __( 'Cards Multi Badge', 'elementor-pro' );
}
}
// register the skin to the posts widget
$widget->add_skin( new cards_multi_badge_skin( $widget ) );
} );
However, this code does not work? Anybody who has an idea what I'm doing wrong?
I modified my posts widget in Elementor with a custom skin in order to show multiple badges with following code:
/* MULTIPLE BADGES ON POST */
/* --- */
add_action( 'elementor/widget/posts/skins_init', function( $widget ) {
class cards_multi_badge_skin extends \ElementorPro\Modules\Posts\Skins\Skin_Cards {
protected function render_badge() {
$taxonomy = $this->get_instance_value( 'badge_taxonomy' );
if ( empty( $taxonomy ) ) {
return;
}
$terms = get_the_terms( get_the_ID(), $taxonomy );
if ( ! is_array( $terms ) ) {
return;
}
?><div class="elementor-post__badges"><?php
foreach( $terms as $term ) : ?>
<div class="elementor-post__badge"><?php echo $term->name; ?></div>
<?php endforeach; ?>
</div>
<?php
}
public function get_id() {
return 'cards_multi_badge';
}
public function get_title() {
return __( 'Cards Multi Badge', 'elementor-pro' );
}
}
// register the skin to the posts widget
$widget->add_skin( new cards_multi_badge_skin( $widget ) );
} );
This leads to following result:
Now, I'm trying the same for the archive posts widget in Elementor with following code:
/* MULTIPLE BADGES ON ARCHIVE POST */
/* --- */
add_action( 'elementor/widget/archive-posts/skins_init', function( $widget ) {
class cards_multi_badge_skin extends \ElementorPro\Modules\Archive_Posts\Skins\Skin_Cards {
protected function render_badge() {
$taxonomy = $this->get_instance_value( 'badge_taxonomy' );
if ( empty( $taxonomy ) ) {
return;
}
$terms = get_the_terms( get_the_ID(), $taxonomy );
if ( ! is_array( $terms ) ) {
return;
}
?><div class="elementor-post__badges"><?php
foreach( $terms as $term ) : ?>
<div class="elementor-post__badge"><?php echo $term->name; ?></div>
<?php endforeach; ?>
</div>
<?php
}
public function get_id() {
return 'cards_multi_badge';
}
public function get_title() {
return __( 'Cards Multi Badge', 'elementor-pro' );
}
}
// register the skin to the posts widget
$widget->add_skin( new cards_multi_badge_skin( $widget ) );
} );
However, this code does not work? Anybody who has an idea what I'm doing wrong?
Share Improve this question asked Apr 24, 2021 at 12:37 BarrieOBarrieO 992 silver badges12 bronze badges1 Answer
Reset to default 2I have the same problem and just find out that you need to extend from. \ElementorPro\Modules\ThemeBuilder\Skins\Posts_Archive_Skin_Cards rather then \ElementorPro\Modules\Posts\Skins\Skin_Cards
本文标签: pluginsExtend Elementor Archive Posts widget with a custom skin in order to show multiple badges
版权声明:本文标题:plugins - Extend Elementor Archive Posts widget with a custom skin in order to show multiple badges 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741576624a2386322.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论