items from a WP_Query. * * @param array $attrs Module attributes. * * @return string */ protected static function render_news($attrs) { $post_type = self::get_attr($attrs, 'module.advanced.postType', 'post'); $categories = self::get_attr($attrs, 'module.advanced.includeCategories', ''); $order_by = self::get_attr($attrs, 'module.advanced.orderBy', 'date'); // Newest first, matching WP_Query and divi/blog. Keep in step with the // `order` default in module.json — see the note in PostCarousel. $order = self::get_attr($attrs, 'module.advanced.order', 'DESC'); $news_count = (int) self::get_attr($attrs, 'module.advanced.newsCount', '5'); $offset = (int) self::get_attr($attrs, 'module.advanced.postOffset', '0'); $exclude = self::get_attr($attrs, 'module.advanced.excludePosts', ''); $query_args = [ 'posts_per_page' => $news_count > 0 ? $news_count : 5, 'post_type' => sanitize_text_field($post_type), 'post_status' => 'publish', 'orderby' => sanitize_text_field($order_by), 'order' => sanitize_text_field($order), 'offset' => $offset, ]; if ('post' === $post_type && '' !== $categories) { $query_args['cat'] = sanitize_text_field($categories); } if ('' !== $exclude) { $ids = array_filter(array_map('absint', array_map('trim', explode(',', $exclude)))); if (!empty($ids)) { $query_args['post__not_in'] = $ids; } } $query = new \WP_Query($query_args); $output = ''; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $output .= sprintf( '
  • %2$s
  • ', esc_url(get_the_permalink()), esc_html(get_the_title()) ); } } wp_reset_postdata(); if ('' === $output) { $output = '
  • ' . esc_html__('No News Found', 'addons-for-divi') . '
  • '; } return $output; } /** * Render the News Ticker module. * * @param array $attrs Module attributes. * @param string $content Inner content. * @param \WP_Block $block Block instance. * @param object $elements Elements helper. * * @return string */ public static function render_callback($attrs, $content, $block, $elements) { $use_title = self::get_attr($attrs, 'module.advanced.useTitle', 'on'); $title_text = DynamicValue::resolve(self::get_attr($attrs, 'module.advanced.titleText', '')); // A cleared Title Text printed an empty title box, which keeps its // padding and background (#112). The builder showed "Breaking News" // in the same case (#91). Both now leave the box out. $title_html = ''; if ('on' === $use_title && TextValue::visible($title_text)) { $title_html = sprintf('
    %1$s
    ', esc_html($title_text)); } // WCAG 2.2.2 (Pause, Stop, Hide): the ticker scrolls automatically and // indefinitely, so it must offer a way to stop it. frontend.js toggles // `.dtq-news-tricker--paused`, which halts the CSS animation. $pause_html = sprintf( '', esc_attr__('Pause the scrolling news ticker', 'addons-for-divi') ); $children = sprintf( '
    %1$s
    %3$s
    ', $title_html, self::render_news($attrs), $pause_html ); return Module::render( [ 'orderIndex' => $block->parsed_block['orderIndex'] ?? 0, 'storeInstance' => $block->parsed_block['storeInstance'] ?? null, 'attrs' => $attrs, 'elements' => $elements, 'id' => $block->parsed_block['id'] ?? '', 'name' => $block->block_type->name ?? '', 'moduleClassName' => 'dtq_news_ticker', 'classnamesFunction' => [self::class, 'module_classnames'], 'stylesComponent' => [self::class, 'module_styles'], 'scriptDataComponent' => [self::class, 'module_script_data'], 'children' => [ $elements->style_components(['attrName' => 'module']), $children, ], ] ); } }