Table of Contents:
Fixed a bug in render function for alt text
public function render() {
$settings = $this->settings;
// Fetch settings with defaults
$logo_count = $this->countItems($settings['logoRepeater']);
echo $logo_count;
// Set CSS variable for logo count
$this->set_attribute('_root', 'style', sprintf(
'--logo-count: %d;',
intval($logo_count)
));
// Add classes for scroll direction
$scroll_direction = isset($settings['scrollDirection']) ? esc_attr($settings['scrollDirection']) : 'rtl';
$root_classes = ['logo-scroll', 'scroll-' . $scroll_direction];
$this->set_attribute('_root', 'class', $root_classes);
// Render the root container with all attributes
echo "<div {$this->render_attributes('_root')}>";
?>
<div class="logo-scroll__wrap">
<?php
if (!empty($settings['logoRepeater'])) {
foreach ($settings['logoRepeater'] as $field) {
if (!empty($field['MediaItem']['url'])) {
// Get the image ID from the URL or the field
$image_id = attachment_url_to_postid($field['MediaItem']['url']);
// Get the alt text using wp_get_attachment_image_alt()
$alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
// Fallback if no alt text is set
if (empty($alt_text)) {
$alt_text = 'Logo Image';
}
?>
<figure>
<img src="<?php echo esc_url($field['MediaItem']['url']); ?>" alt="<?php echo esc_attr($alt_text); ?>">
</figure>
<?php
}
}
// Duplicate logos for seamless scrolling
foreach ($settings['logoRepeater'] as $field) {
if (!empty($field['MediaItem']['url'])) {
$image_id = attachment_url_to_postid($field['MediaItem']['url']);
$alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
if (empty($alt_text)) {
$alt_text = 'Logo Image';
}
?>
<figure>
<img src="<?php echo esc_url($field['MediaItem']['url']); ?>" alt="<?php echo esc_attr($alt_text); ?>">
</figure>
<?php
}
}
}
?>
</div>
<?php
echo "</div>";
}
In this mini course, you will learn how to build your own element using the Bricks Child Theme.
The course will show you how to build a custom infinite scrolling Logo section that clients absolutely love to see on their homepage!
Want to buy this course? Check out the build your own Bricks elements product page! or check out the demo to see what you can build from this course
The infinite scrolling logo section is a marquee section that animates your logos across the screen.
This is a premium tutorial and you can purchase it on the Build Your Own Elements With Bricks product page.