bootscore/bs-swiper

Replace featured image with video from posts?

Closed this issue · 5 comments

First, thanks for this plugin...it's awesome! I am using the "sc-swiper-card.php" template to pull the posts into the carousel. I have a post category titled "youtube" which contains only youtube videos. Right now, the slider only displays the youtube thumbnail which does not link to or play the youtube video from the posts. I would like to pull both the youtube thumbnail and the actual embeded video from the youtube category posts and have it placed where the featured image normally is for the template as well as have it clickable/playable. Is there a way to modify the "featured image" portion of code in the template to do this?

Thank you!

You can do this with ACF https://wordpress.org/plugins/advanced-custom-fields/.

Check example here https://dev.bootscore.me/plugins/bs-swiper/.

  • Install plugin
  • Create a field group
  • Create a text field and name it youtube
  • Add <?php the_field('youtube'); ?> direct below <?php the_post_thumbnail('medium', array('class' => 'card-img-top')); ?> in sc-swiper-card.php in your child's copy:
<!-- Featured Image-->
<?php the_post_thumbnail('medium', array('class' => 'card-img-top')); ?>
<!-- Youtube -->
<?php the_field('youtube'); ?>
  • Copy Youtube embed code and paste it in post edit screen in the new youtube field (show video in the loop)
  • Copy Youtube video link and embed it with video block on the top of the page.

Insert featured image only in non-youtube category posts.

Does this help?

Thanks for the quick response!

I added the ACF field and everything works great! The only problem I have is that I have multiple sliders on the same page showing different social media posts. For example, I have a slider for youtube posts and one for Twitter. If I comment out the code for the featured image, it works great for the youtube slider but also removes the featured image for the other sliders as well. Is there a way to add a section to the code saying something like "if the category is [some category] use ACF field only, not featured image"? Or maybe a way to have separate shortcodes for sliders with featured image and those with video? Sorry if that is asking too much and I understand if that is not possible. Thanks for your help!

Much more simpler.

Don‘t comment out the featured image code. Leave the featured image in youtube posts blank and add embed code to the ACF field. Then show in first block after heading your video again. Youtube category will show video in loop and post, just like a featured image.

For all other posts, don‘t insert something in the ACF field. Use featured image for them. So you can mix all categories.

Solved?

Yes, much simpler...solved and works perfectly!

There aren't many (good) Bootstrap5/Wordpress integrations out there that truly adhere to Bootstrap standards. Your themes/plugins are by far the best. Thanks again.

You‘re welcome 👍