WP Residence Help WP Residence Help

  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required, WpResidence 5.0 / Understanding and Extending blog post carousel in WpResidence Theme

Understanding and Extending blog post carousel in WpResidence Theme

145 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

Related Articles

  • Introduction to WPResidence Header Customization
  • Understanding WPResidence Header Types: An Overview
  • Customizing the WPResidence Logo Display
  • Configuring the Primary Navigation Menu in WPResidence

WP Residence Documentation

  • 1. General
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 2. Installation
  • 3. Installation FAQ
  • 4. Advanced Search
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 5. Agent, Agency & Developers
  • 6. Property Page
  • 7. Properties List
  • 8. Property Taxonomies
  • 9. Property Custom Template
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • Theme Options
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • Translation
  • FAQ
  • Pages
  • Header
  • Footer
  • Google or Open Street Maps
  • Payment Options
  • Plugins
    • Included Plugins
    • Third Party Plugins – IDX Compatibility
    • Third Party Plugins – Multi Languages
    • Third party Plugins – Other
  • Technical
    • Technical how to | Custom Code Required
    • Technical: Child Theme
  • Theme Updates

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API