WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required, WPResidence 5.0 Documentation / Understanding and Extending blog post carousel in WpResidence Theme

Understanding and Extending blog post carousel in WpResidence Theme

570 views 0

The postslider.php file, located at templates/blog_post/postslider.php in the WpResidence theme, is responsible for displaying a carousel of images or videos at the top of blog posts. This component enhances the visual appeal of your blog posts and allows for showcasing multiple media items.

File Structure and Functionality

Let’s break down the file structure and explain its functionality step by step:

1. Checking for Group Pictures


<?php
if (esc_html(get_post_meta($post->ID, 'group_pictures', true)) != 'no') {
// Rest of the code
}
?>

This conditional statement checks if group pictures are enabled for the post. The get_post_meta() function, found in wp-includes/post.php, retrieves the ‘group_pictures’ meta value for the current post.

2. Retrieving Post Attachments


$arguments = array(
'numberposts' => -1,
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_status' => null,
'orderby' => 'menu_order',
'post_mime_type' => 'image',
'order' => 'ASC'
);
$post_attachments = get_posts($arguments);

This code retrieves all image attachments for the current post. The get_posts() function, located in wp-includes/post.php, is used to fetch the attachments.

3. Retrieving Video Information


$video_id = esc_html(get_post_meta($post->ID, 'embed_video_id', true));
$video_type = esc_html(get_post_meta($post->ID, 'embed_video_type', true));

These lines retrieve the video ID and type if a video is associated with the post. The get_post_meta() function is used again here.

4. Creating the Carousel Structure


<div id="wpresidence-blog-post-carousel-bootstrap" class="carousel slide post-carusel">
<ol class="carousel-indicators">
<!-- Indicators code here -->
</ol>
<div class="carousel-inner">
<!-- Carousel items code here -->
</div>
<!-- Navigation controls here -->
</div>

This section creates the basic structure for the Bootstrap carousel. The CSS classes used here (e.g., ‘carousel’, ‘post-carusel’) can be found in the _wpresidence_carousels.scss file in the theme’s css directory.

5. Adding Carousel Indicators


<?php
$counter = 0;
$has_video = 0;
if ($video_id != '') {
$has_video = 1;
$counter = 1;
echo '<button data-bs-target="#wpresidence-blog-post-carousel-bootstrap" data-bs-slide-to="0" class="active"></button>';
}
if (!empty($post_attachments)) {
foreach ($post_attachments as $attachment) {
$counter++;
$active = ($counter == 1 && $has_video != 1) ? "active" : "";
echo '<button data-bs-target="#wpresidence-blog-post-carousel-bootstrap" data-bs-slide-to="' . ($counter - 1) . '" class="' . $active . '"></button>';
}
}
?>

This code generates the carousel indicators, creating a button for each slide (video and images).

6. Adding Carousel Items


<?php
if ($video_id != '') {
echo '<div class="item carousel-item active">';
if ($video_type === 'vimeo') {
echo wpestate_custom_vimdeo_video($video_id);
} else {
echo wpestate_custom_youtube_video($video_id);
}
echo '</div>';
}
if (!empty($post_attachments)) {
$counter = 0;
foreach ($post_attachments as $attachment) {
$counter++;
$active = ($counter == 1 && $has_video != 1) ? "active" : "";
$full_img = wp_get_attachment_image_src($attachment->ID, 'listing_full_slider');
$full_prty = wp_get_attachment_image_src($attachment->ID, 'full');
$attachment_meta = wp_get_attachment($attachment->ID);
// Echo carousel item HTML here
}
}
?>

This section adds the actual carousel items, including the video (if present) and all image attachments. The wpestate_custom_vimdeo_video() and wpestate_custom_youtube_video() functions can be found in the theme’s functions.php file.

Extending Functionality

To extend or modify the postslider.php functionality, consider these examples:

1. Adding Captions to Images

To display image captions, you can modify the carousel item code:


echo '<div class="item carousel-item ' . $active . '">';
echo '<img src="' . esc_url($full_img[0]) . '" alt="' . esc_attr($attachment_meta['alt']) . '" class="img-responsive lightbox_trigger" />';
if (!empty($attachment_meta['caption'])) {
echo '<div class="carousel-caption">' . esc_html($attachment_meta['caption']) . '</div>';
}
echo '</div>';

2. Changing Slider Behavior

To modify the slider behavior, you can add data attributes to the main carousel div:


<div id="wpresidence-blog-post-carousel-bootstrap" class="carousel slide post-carusel" data-bs-ride="carousel" data-bs-interval="5000" data-bs-wrap="true">

This sets the carousel to automatically cycle every 5 seconds and to loop continuously.

3. Adding Lightbox Functionality

To enable a lightbox for the images, you can wrap the image in a link:


echo '<a href="' . esc_url($full_prty[0]) . '" data-lightbox="post-images" data-title="' . esc_attr($attachment_meta['caption']) . '">';
echo '<img src="' . esc_url($full_img[0]) . '" alt="' . esc_attr($attachment_meta['alt']) . '" class="img-responsive lightbox_trigger" />';
echo '</a>';

Note: This requires adding a lightbox library to your theme.

By understanding the structure and functionality of postslider.php, you can customize the post slider to better fit your needs in the WpResidence theme. Remember to make these changes in a child theme to prevent them from being overwritten during theme updates.

[Previous content remains the same up to the “File Structure and Functionality” section]

CSS Classes and Their Locations

The postslider.php file uses several CSS classes to style the carousel. Here’s a breakdown of these classes and where you can find them in the theme structure:

1. Main Carousel Classes

Classes: carousel, slide, post-carusel

Location: These classes are primarily styled in the file wp-content/themes/wpresidence/css/_wpresidence_carousels.scss. For example:


.post-carusel {
.carousel-indicators {
gap: 3px;
button {
// Styles for carousel indicators
}
}
}

2. Carousel Item Classes

Classes: item, carousel-item, active

Location: These classes are also styled in _wpresidence_carousels.scss, but some basic styles might be inherited from Bootstrap. WpResidence-specific styles can be found like this:


.carousel-item {
// WpResidence-specific styles for carousel items
}

3. Image Classes

Classes: img-responsive, lightbox_trigger

Location: The img-responsive class is a Bootstrap class, but it might be overridden in wp-content/themes/wpresidence/css/css-images.css. The lightbox_trigger class is likely styled in the same file:


.img-responsive {
// Responsive image styles
}
.lightbox_trigger {
// Styles for lightbox trigger images
}

4. Video Container Classes

If videos are embedded, they might use classes like video-container or embed-responsive.

Location: These classes are typically styled in wp-content/themes/wpresidence/css/video.css:


.video-container {
// Styles for video containers
}
.embed-responsive {
// Styles for responsive embeds
}

5. Navigation Control Classes

Classes: carousel-control-prev, carousel-control-next, wpresidence-carousel-control

Location: These are styled in wp-content/themes/wpresidence/css/_wpresidence_carousels.scss:


.wpresidence-carousel-control {
width: 40px;
height: 40px;
// More styles for carousel controls
}

To customize these styles, it’s recommended to add your CSS to a child theme’s style.css file or use the theme’s custom CSS option if available. This ensures your changes won’t be overwritten during theme updates.

Technical how to | Custom Code RequiredWPResidence 5.0 Documentation

Related Articles

  • Webhook Integration for Contact Forms
  • Technical: Change the Schedule Tour Email Text and the Form Default Message
  • Property list filter customization
  • Technical – How to Change the Minimum Image Dimensions for Property Uploads in WPResidence

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API