block_name ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker__label', $this->get_label_css( $attributes ), $this->get_label_css( $attributes, 'Tablet' ), $this->get_label_css( $attributes, 'Mobile' ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker__label:hover', $this->get_label_color_hover_css( $attributes ), $this->get_label_color_hover_css( $attributes, 'Tablet' ), $this->get_label_color_hover_css( $attributes, 'Mobile' ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker', $this->get_ticker_content_css( $attributes ), $this->get_ticker_content_css( $attributes, 'Tablet' ), $this->get_ticker_content_css( $attributes, 'Mobile' ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker__marquee', $this->get_ticker_color_css( $attributes ), $this->get_ticker_color_css( $attributes, 'Tablet' ), $this->get_ticker_color_css( $attributes, 'Mobile' ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker__marquee:hover', $this->get_ticker_color_hover_css( $attributes ), $this->get_ticker_color_hover_css( $attributes, 'Tablet' ), $this->get_ticker_color_hover_css( $attributes, 'Mobile' ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker--icons', $this->get_navigator_css( $attributes ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker--icons__prev', $this->get_navigator_color_css( $attributes ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker--icons__next', $this->get_navigator_color_css( $attributes ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker--icons__pause', $this->get_navigator_color_css( $attributes ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker--icons__resume', $this->get_navigator_color_css( $attributes ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker__list', $this->get_ticker_list_styles_css( $attributes ), $this->get_ticker_list_styles_css( $attributes, 'Tablet' ), $this->get_ticker_list_styles_css( $attributes, 'Mobile' ) ); $css_generator->add_class_styles( '{{WRAPPER}} .ablocks-block-news-ticker--date', $this->get_show_time_css( $attributes ) ); return $css_generator->generate_css(); } public function get_label_css( $attributes, $device = '' ) { $label_css = []; if ( isset( $attributes['isShowLabel'] ) && $attributes['isShowLabel'] ) { $label_css['display'] = 'flex'; } else { $label_css['display'] = 'none'; } if ( isset( $attributes['labelPosition'] ) && $attributes['labelPosition'] === 'right' ) { $label_css['right'] = '0'; $label_css['left'] = 'auto'; } else { $label_css['left'] = '0'; $label_css['right'] = 'auto'; } if ( ! empty( $attributes['tickerLabelShape'] ) ) { switch ( $attributes['tickerLabelShape'] ) { case 'small': $label_css['clip-path'] = 'polygon(0% 0%, 80% 0%, 100% 50%, 80% 100%, 0% 100%)'; break; case 'medium': $label_css['clip-path'] = 'polygon(0% 0%, 85% 0%, 100% 50%, 85% 100%, 0% 100%)'; break; case 'large': $label_css['clip-path'] = 'polygon(0% 0%, 90% 0%, 100% 50%, 90% 100%, 0% 100%)'; break; default: $label_css['clip-path'] = ''; break; } } $typographyValueGlobal = ! empty( $attributes['labelTypographyGlobal'] ) ? $attributes['labelTypographyGlobal'] : array(); $typography_css = ! empty( $attributes['labelTypography'] ) ? Typography::get_css( $attributes['labelTypography'], '', $device, $typographyValueGlobal ) : array(); $textShadowCss = ! empty( $attributes['labelTextShadow'] ) ? TextShadow::get_css( $attributes['labelTextShadow'], '', $device ) : array(); $textStrokeCss = ! empty( $attributes['labelTextStroke'] ) ? TextStroke::get_css( $attributes['labelTextStroke'], '', $device ) : array(); return array_merge( [ 'color' => Color::get_css( isset( $attributes['labelColor'] ) ? $attributes['labelColor'] : '' ) ], [ 'background' => Color::get_css( isset( $attributes['labelBackgroundColor'] ) ? $attributes['labelBackgroundColor'] : '' ) ], Range::get_css([ 'attributeValue' => $attributes['labelPadding'], 'attribute_object_key' => 'value', 'isResponsive' => true, 'defaultValue' => 10, 'hasUnit' => true, 'unitDefaultValue' => 'px', 'property' => 'padding', 'device' => $device, ]), $label_css, $typography_css, $textShadowCss, $textStrokeCss ); } public function get_label_color_hover_css( $attributes ) { return array_merge( [ 'color' => Color::get_css( isset( $attributes['labelColorH'] ) ? $attributes['labelColorH'] : '' ) ], [ 'background' => Color::get_css( isset( $attributes['labelBackgroundColorH'] ) ? $attributes['labelBackgroundColorH'] : '' ) ], Range::get_css([ 'attributeValue' => $attributes['labelColorTransition'], 'attribute_object_key' => 'value', 'defaultValue' => 0, 'unitDefaultValue' => 's', 'property' => 'transition-duration', ]), ); } public function get_ticker_content_css( $attributes, $device = '' ) { $ticker_content_css = []; if ( isset( $attributes['isPositionSticky'] ) && $attributes['isPositionSticky'] ) { if ( isset( $attributes['stickyPosition'] ) && $attributes['stickyPosition'] === 'up' ) { $ticker_content_css['position'] = 'fixed'; $ticker_content_css['top'] = '32px'; $ticker_content_css['left'] = '0'; $ticker_content_css['width'] = '100%'; } elseif ( isset( $attributes['stickyPosition'] ) && $attributes['stickyPosition'] === 'down' ) { $ticker_content_css['position'] = 'fixed'; $ticker_content_css['bottom'] = '0'; $ticker_content_css['left'] = '0'; $ticker_content_css['width'] = '100%'; } } return array_merge( Range::get_css([ 'attributeValue' => $attributes['tickerHeight'], 'attribute_object_key' => 'value', 'isResponsive' => true, 'defaultValue' => 50, 'hasUnit' => true, 'unitDefaultValue' => 'px', 'property' => 'height', 'device' => $device, ]), $ticker_content_css ); } public function get_ticker_list_styles_css( $attributes, $device = '' ) { $ticker_list_styles_css = []; if ( isset( $attributes['tickerListStyle'] ) ) { switch ( $attributes['tickerListStyle'] ) { case 'none': $ticker_list_styles_css['list-style'] = 'none'; break; case 'circle': $ticker_list_styles_css['list-style'] = 'circle'; break; case 'box': $ticker_list_styles_css['list-style'] = 'square'; break; default: $ticker_list_styles_css['list-style'] = 'none'; } } $typographyValueGlobal = ! empty( $attributes['tickerTypographyGlobal'] ) ? $attributes['tickerTypographyGlobal'] : array(); $typography_css = ! empty( $attributes['tickerTypography'] ) ? Typography::get_css( $attributes['tickerTypography'], '', $device, $typographyValueGlobal ) : array(); $textShadowCss = ! empty( $attributes['tickerTextShadow'] ) ? TextShadow::get_css( $attributes['tickerTextShadow'], '', $device ) : array(); $textStrokeCss = ! empty( $attributes['tickerTextStroke'] ) ? TextStroke::get_css( $attributes['tickerTextStroke'], '', $device ) : array(); return array_merge( $ticker_list_styles_css, $typography_css, $textShadowCss, $textStrokeCss ); } public function get_ticker_color_css( $attributes ) { return array_merge( [ 'color' => Color::get_css( isset( $attributes['tickerColor'] ) ? $attributes['tickerColor'] : '' ) ], [ 'background' => Color::get_css( isset( $attributes['tickerBgColor'] ) ? $attributes['tickerBgColor'] : '' ) ], ); } public function get_ticker_color_hover_css( $attributes ) { return array_merge( [ 'color' => Color::get_css( isset( $attributes['tickerColorH'] ) ? $attributes['tickerColorH'] : '' ) ], [ 'background' => Color::get_css( isset( $attributes['tickerBgColorH'] ) ? $attributes['tickerBgColorH'] : '' ) ], Range::get_css([ 'attributeValue' => $attributes['tickerColorTransition'], 'attribute_object_key' => 'value', 'defaultValue' => 0, 'unitDefaultValue' => 's', 'property' => 'transition-duration', ]) ); } public function get_navigator_css( $attributes ) { $navigator_css = []; if ( isset( $attributes['showTickerNavigator'] ) && $attributes['showTickerNavigator'] ) { $navigator_css['display'] = 'flex'; } else { $navigator_css['display'] = 'none'; } if ( isset( $attributes['navigatorPosition'] ) && $attributes['navigatorPosition'] === 'right' ) { $navigator_css['right'] = '0'; $navigator_css['left'] = 'auto'; } else { $navigator_css['left'] = '0'; $navigator_css['right'] = 'auto'; } return $navigator_css; } public function get_navigator_color_css( $attributes ) { return [ 'background' => Color::get_css( isset( $attributes['navigatorBgColor'] ) ? $attributes['navigatorBgColor'] : '' ) ]; } public function get_show_time_css( $attributes ) { $time_show_css = []; if ( isset( $attributes['isShowTime'] ) && $attributes['isShowTime'] ) { $time_show_css['display'] = 'inline'; } else { $time_show_css['display'] = 'none'; } return $time_show_css; } public function render_block_content( $attributes, $content, $block_instance ) { $sticky_label = sanitize_text_field( $attributes['stickyLabel'] ?? 'Breaking News' ); $sticky_label_tag = sanitize_html_class( $attributes['stickyLabelTag'] ?? 'span' ); $selected_posts = array_map( 'absint', $attributes['selectedPosts'] ?? [] ); $selected_pages = array_map( 'absint', $attributes['selectedPages'] ?? [] ); $slide_speed = sanitize_text_field( $attributes['slideSpeed'] ?? '2' ); $is_pause_on_over = filter_var( $attributes['isPauseOnOver'] ?? false, FILTER_VALIDATE_BOOLEAN ); $show_ticker_navigator = filter_var( $attributes['showTickerNavigator'] ?? false, FILTER_VALIDATE_BOOLEAN ); $custom_text = sanitize_text_field( $attributes['customText'] ?? '' ); $query_type = sanitize_text_field( $attributes['queryType'] ?? '' ); $navigator_color = Color::get_css( isset( $attributes['navigatorColor'] ) ? $attributes['navigatorColor'] : '' ); $slide_direction = sanitize_text_field( $attributes['slideDirection'] ?? 'left' ); $post_type = ! empty( $selected_pages ) ? 'page' : 'post'; $selected_items = ! empty( $selected_pages ) ? $selected_pages : $selected_posts; $args = [ 'post_type' => $post_type, 'post__in' => $selected_items, 'orderby' => 'post__in', 'posts_per_page' => -1, ]; $query = new \WP_Query( $args ); ob_start(); ?>
< class="ablocks-block-news-ticker__label"> >
  • >
  • have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); $has_link = ! empty( $attributes['pageLink'] ) || ! empty( $attributes['postLink'] ); $post_link = get_permalink(); $link_target = '_blank'; $title = get_the_title(); $date = esc_html( $this->get_relative_time( get_the_date() ) ); ?>
diff( $post_date ); $weeks = floor( $interval->days / 7 ); if ( $weeks >= 1 ) { return $weeks . ' week' . ( $weeks > 1 ? 's' : '' ) . ' ago'; } return 'Less than a week ago'; } }