Bootstrap Carousel Thumbnail Silider with PHP codeigniter - php

I am trying to get a bootstrap carousel to perform like this example below but with some php code.
http://www.bootply.com/81478
But with php code where it has row and columns. I have 5 images that I have displayed but each one for some reason comes in as a new slide.
It should show about 4 - 5 images on one row. But with my php code does not seem to work properly only shows one image each slide.
My Question is: In my view is there any way to be able to make each slide to display about 4 images.
My View Is
<div id="carousel-thumbnail<?php echo $module;?>" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php foreach ($banners as $i => $banner) { ?>
<li data-target="#carousel-thumbnail<?php echo $module; ?>" data-slide-to="<?php echo $i; ?>"<?php echo !$i ? ' class="active"' : ''; ?>></li>
<?php } ?>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php foreach ($banners as $i => $banner) { ?>
<div class="item<?php echo !$i ? ' active' : ''; ?>">
<div class="row">
<div class="col-lg-3">
<img src="<?php echo $banner['src']; ?>" class="img-thumbnail">
</div>
</div>
</div>
<?php } ?>
</div>
<!-- Controls -->
<?php if (count($banners) > 1) { ?>
<a class="carousel-control left" href="#carousel-thumbnail<?php echo $module; ?>" data-slide="prev">‹</a>
<a class="carousel-control right" href="#carousel-thumbnail<?php echo $module; ?>" data-slide="next">›</a>
<?php } ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#carousel<?php echo $module;?>').carousel({
interval: 10000
});
});
</script>
My Controller
<?php
class Carousel extends MX_Controller {
public function __construct() {
parent::__construct();
}
public function index($info) {
static $module = 0;
$data['banners'] = array();
$banners = $this->get_banner($info[0]['module_display_id']);
foreach ($banners as $banner) {
if (is_file(FCPATH . 'images/' . $banner['banner_image'])) {
$data['banners'][] = array(
'src' => base_url() . 'images/' . $banner['banner_image']
);
} else {
$data['banners'][] = array(
'src' => $banner['banner_image']
);
}
}
$data['module'] = $module++;
$this->load->view('theme/default/template/module/carousel', $data);
}
public function get_banner($banner_id) {
$this->db->select('*');
$this->db->from('banner b', 'LEFT');
$this->db->join('banner_image bi', 'bi.banner_id = b.banner_id', 'LEFT');
$this->db->where('b.banner_id', $banner_id);
$this->db->where('b.banner_status', '1');
$this->db->order_by('banner_sort_order', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
}

PHP code for groups of four images
Indicators
Each item is a group of four images. The indicator indicates the group, rather than the image. Therefore, the number of indicators is four times less than the number of images.
<!-- Indicators -->
<ol class="carousel-indicators">
<?php for ($i = 0; $i < ceil(count($banners) / 4); $i++) { ?>
<li data-target="#carousel-thumbnail<?php echo $module; ?>" data-slide-to="<?php echo $i; ?>"<?php echo !$i ? ' class="active"' : ''; ?>></li>
<?php } ?>
</ol>
Items
You need to wrap in the row a series of four slide, rather than one by one:
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php foreach ($banners as $i => $banner) { ?>
<?php if (($i > 0) && ($i % 4 == 0)) { ?>
</div>
</div>
<div class="item">
<div class="row">
<?php } ?>
<div class="col-lg-3">
<img src="<?php echo $banner['src']; ?>" class="img-thumbnail">
</div>
<?php } ?>
</div>
</div>
</div>

Related

Loading images to Bootstrap carousel from a MySQL database using PDO (fetchall problem)

I'm using PDO to insert images from a database to a Bootstrap carousel. By that I mean ( loading The image path ), but the problem is when I use fetchall(); or fetch I get all rows value like this:
require_once '..\Config.php';
$dbCon = "mysql:host=$host;dbname=$db_name";
$conn = new PDO($dbCon, $username, $password);
$getquery = $conn->prepare('SELECT (imageurl) FROM special');
$getquery->execute();
$result = $getquery->fetchall();
echo $result['imageurl'];
The output is: Efexor.jpg path upload/17.jpg upload/17.jpg upload/19.jpg upload/18.jpg upload/18.jpg* that is all rows from imageurl column, so when I loop foreach ($result) to load images from database to a Bootstrap carousel. It dose't work
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
<?
$i = 0;
foreach($result as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<li data-target="#demo" data-slide-to="<?= $i; ?>" class="<?= $actives;?>"></li>
<? $i++ ; }?>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<?
$i = 0;
foreach($result as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<div class="carousel-item <?= $actives;?>">
<img src="<?= $row['imageurl']?>">
</div>
<? echo $row['imageurl'];?>
<? $i++; }?>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
Try like this:
<!-- The slideshow -->
<div class="carousel-inner">
<?
$i = 0;
$full_url = 'YOUR URL AND PATH TO IMAGE FOLDER HERE';
foreach($result as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<div class="carousel-item <?= $actives;?>">
<img src="<?= $full_url . $row['imageurl']?>">
</div>
<? echo $full_url . $row['imageurl'];?>
<? $i++; }?>
</div>

php two arrays into string

With php print_r I got final result as :
Array ( [0] => 31 [1] => 21 ) Array ( [0] => 33 [1] => 27 )
And I want result to be like 31,21,33,27.
I am stuck up. Please guide me through.
Thanks,
Vikram
**Please bare with lengthy stuff. **
I have 2 main categories and need to display 3 fourth level children on home page. Categories are like :
Category > Clothing.
Category > Clothing > Mens.
Category >> Clothing > Mens > Top.
Category > Clothing > Mens > Top > Jeans.
CODES
<div class="container products" data-aos="fade-down">
<div class="page-titles" data-aos="fade-up">
Products
<hr />
</div>
<!--page-titles-->
<?php
$homepage_products=get_post_meta($post->ID, 'homepage_products', TRUE);
$homepage_parent=explode(',', $homepage_products);
global $parent_one;
global $x;
$x=1;
foreach($homepage_parent as $parent_one)
{
$parent_one_title = get_the_title( $parent_one );
$content_post = get_post($parent_one);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
?>
<div class="row clothing">
<div id="<?php echo $x++; ?>" class="col-xs-12 col-sm-12 col-md-4 col-lg-4
<?php if($x % 2)
{
echo 'col-md-push-8 col-lg-push-8';
}
?>
">
<?php echo get_the_post_thumbnail($parent_one, 'medium_large', array('class' => 'img-'.$x)); ?>
</div>
<!--col-4 img-->
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8
<?php if($x % 2)
{
echo 'col-md-pull-4 col-lg-pull-4';
}
?>
">
<h2><?php echo $parent_one_title; ?></h2>
<?php echo $content; ?>
<!-- child pages of <?php echo strtolower($parent_title); ?> starts-->
<div class="row">
<?php
$parent_two=get_pages( array('parent'=>$parent_one,'child_of'=>$parent_one) );
foreach($parent_two as $parent_two_ids)
{
$parent_two_id=$parent_two_ids->ID;
$parent_two_id.=",";
$parent_three=get_pages( array('parent'=>$parent_two_id) );
$str_id = array();
foreach($parent_three as $parent_three_ids)
{
$parent_three_id=$parent_three_ids->ID;
$parent_three_id.=',';
$parent_four=get_pages( array('parent'=>$parent_three_id) );
$four_ids=array();
foreach($parent_four as $parent_four_ids)
{
$four_id=$parent_four_ids->ID;
$four_ids[]=$four_id;
}//parent_four_ids
// HERE IS MY ISSUE //
echo implode(',', array_merge($four_ids) );
// HERE IS MY ISSUE //
//$ids=implode(',',$four_ids);
//$idx=$ids;
//$idv=preg_replace('#\s+#',',',trim($idx));
//echo $idv;
//$str_id[]=$idx;
//$str_idx=implode(',',$str_id);
//echo $str_idx;
$content=apply_filters('the_content', $parent_four_ids->post_content);
$c_length = 80;
if (strlen($content) > $c_length)
{
$content = wordwrap($content, 80);
$i = strpos($content, "\n");
if ($i) {
$content = substr($content, 0, $i);
}
}
?>
<!-- <div class="col-xs-12 col-sm-12 col-md-3 col-lg-3 product">
< ?php echo get_the_post_thumbnail($parent_four_ids, 'medium_large'); ?>
<a href="< ?php echo get_permalink($parent_four_ids);?>">
<h4>< ?php echo $parent_four_ids->post_title; ?></h4>
</a>
< ?php echo $content; ?>
</div><!--col 3 #< ?php echo $parent_four_ids->ID; ?>-->
<?php
}//parent_three_ids
} // parent_two_ids
?>
</div>
<!-- row category - slider- child pages of <?php echo strtolower($parent_one_title); ?> ends-->
</div>
<!-- col-6 content - child pages-->
</div>
<!--row <?php echo strtolower($parent_title); ?>-->
<? } //home_parent ?>
</div>
<!--container products-->
Just as iainn said above:
php > echo implode(',', array_merge([31, 21], [33, 27]));
31,21,33,27
If you wanted a single array and not a string, remove the implode() call.

Items per slide responsive

I've made a logo slider using Bootstrap (basically as seen here http://jsfiddle.net/juddlyon/Q2TYv/10/).
Within each slide there are 4 logos. I want to make this responsive, where on smaller screens it only shows 2 logos per slide. I'm not sure what the best way is to do this.
I can double the grid-4 width to 50% with media queries but then it will still show 4 per slide, in a 2x2 grid.
Another way is to duplicate the entire slide and hide and show the correct one, but this seems like a rather inefficient appreach.
So really I need to reduce the number of logos per slide as it is loaded.. but how?
I'm using WP and Advanced Custom Fields to populate the slider. Simplified code below:
PHP:
<?php
$firstslide = 0;
$slide = 0;
$repeater = get_field('clients', $clients);
$order = array();
foreach( $repeater as $i => $row ) {
$order[ $i ] = $row['name'];
}
array_multisort($order, SORT_ASC, $repeater);
if($repeater):
foreach($repeater as $i => $row):
if ($firstslide == 0) {
$class = "item active";
} else {
$class = "item";
};
if ($slide == 0) {
echo '<div class="' . $class . '">';
};
?>
<div class="grid-4">
<img src="<?php echo $row['logo']; ?>">
</div>
<?php
if ($slide == 4) {
echo '</div>';
$slide = 0;
} else {
$slide++;
}
$firstslide++;
endforeach;
wp_reset_postdata();
endif;
?>
This would results in something like:
<div class="item active">
<div class="grid-4"><img src="logo1.jpg"></div>
<div class="grid-4"><img src="logo2.jpg"></div>
<div class="grid-4"><img src="logo3.jpg"></div>
<div class="grid-4"><img src="logo4.jpg"></div>
</div>
<div class="item">
<div class="grid-4"><img src="logo5.jpg"></div>
<div class="grid-4"><img src="logo6.jpg"></div>
<div class="grid-4"><img src="logo7.jpg"></div>
<div class="grid-4"><img src="logo8.jpg"></div>
</div>
<div class="item">
<div class="grid-4"><img src="logo9.jpg"></div>
<div class="grid-4"><img src="logo10.jpg"></div>
<div class="grid-4"><img src="logo11.jpg"></div>
<div class="grid-4"><img src="logo12.jpg"></div>
</div>
Very simplified CSS for the grid:
.grid-4 {
width: 25%;
}
After more searching, it looks like Slick is a solution that will just take care this.
jsfiddle.net/BishopBarber/ufnjkjy4/1/

Every/other CSS techniques

I am creating a page with 4 different sections. In each section there is a responsive image and on the image there is text and some buttons. Right now they are aligned a bit off center and to the right. I am trying to achieve so that the 1st div the text and buttons float right and the 2nd div the text and buttons float left and so on. I am using the even odd nth property but it is only responding on the even css nth property. Here is the CSS and html. Keep in mind I am just using the background color now as an example and will put in the floats and padding if I get it working.
.popup-open:nth-child(odd) {
background: #ff0000;
}
.popup-open:nth-child(even) {
background: #000000;
}
<div class="popup-open">
<div class="icons-large">
<?php
$fields = CFS()->get('icons_large');
if($fields) :
foreach ($fields as $field) : ?>
<div class="row">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">
</div>
</div>
<?php endforeach; endif; ?>
</div>
<div class="icons-large">
<?php
$fields = CFS()->get('tour_titles');
if($fields) :
foreach ($fields as $field) : ?>
<?php echo $field['tour_name'];?>
<?php endforeach; endif; ?>
</div>
<div class="title"><?php the_title(); ?></div>
</div>
I think you should add a class to the divs and target them that way, you will have more control over it too.
if($fields) :
$i = 1;
foreach ($fields as $field) :
if($i === 2){
$class = "even";
$i = 1;
}else if($i === 1){
$class = "odd";
$i = 2;
}
<div class="row <?=$class;?>">
<div class="image">
<img src="<?php echo $field['icons_big'];?>" alt="">
</div>
</div>
<?php endforeach; endif; ?>

Printing image from array

first off, I'm extremely new to PHP.
I'm using Conrete5, and I have a new template to an image slider. This is what I'm using:
http://codepen.io/altitudems/pen/KdgGLG
There's a placeholder image, which I'm trying to replace by grabbing the first image set in the block itself. Here is my view file from the actual block:
<?php defined('C5_EXECUTE') or die("Access Denied.");
$navigationTypeText = ($navigationType == 0) ? 'arrows' : 'pages';
$c = Page::getCurrentPage();
if ($c->isEditMode()) { ?>
<div class="ccm-edit-mode-disabled-item" style="width: <?php echo $width; ?>; height: <?php echo $height; ?>">
<div style="padding: 40px 0px 40px 0px"><?php echo t('Image Slider disabled in edit mode.')?></div>
</div>
<?php } else { ?>
<script>
$(document).ready(function(){
$(function () {
$("#ccm-image-slider-<?php echo $bID ?>").responsiveSlides({
prevText: "", // String: Text for the "previous" button
nextText: "",
<?php if($navigationType == 0) { ?>
nav:true
<?php } else { ?>
pager: true
<?php } ?>
});
});
});
</script>
<div class="ccm-image-slider-container ccm-block-image-slider-<?php echo $navigationTypeText?>" >
<div class="ccm-image-slider">
<div class="ccm-image-slider-inner">
<?php if(count($rows) > 0) { ?>
<ul class="rslides" id="ccm-image-slider-<?php echo $bID ?>">
<?php foreach($rows as $row) { ?>
<li>
<?php if($row['linkURL']) { ?>
<?php } ?>
<?php
$f = File::getByID($row['fID'])
?>
<?php if(is_object($f)) {
$tag = Core::make('html/image', array($f, false))->getTag();
if($row['title']) {
$tag->alt($row['title']);
}else{
$tag->alt("slide");
}
print $tag; ?>
<?php } ?>
<div class="ccm-image-slider-text">
<?php if($row['title']) { ?>
<h1 class="ccm-image-slider-title"><?php echo $row['title'] ?></h1>
<?php } ?>
<?php echo $row['description'] ?>
</div>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<div class="ccm-image-slider-placeholder">
<p><?php echo t('No Slides Entered.'); ?></p>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
Here is my gallery view file:
<a class="gallery-launcher" href="#gallery1"> // Location of the image
<div class="overlay">
<div class="overlay-content">
<button class="btn btn-default">Open Gallery</button>
</div>
</div>
</a>
<div class="gallery inactive" id="gallery1">
<div class="gallery-item">
//Fullscreen gallery code here
</div>
</div>
Where it says // Location of the image is where I need to have the first image set. I can't figure out what I'd put there? Any help will be appreciated.
You could use the concrete5 file helper to get the file path, like this for example:
$f = File::getByID($row['fID']);
$relpath = $f->getRelativePath();
In general I suggest that you read more about the concrete5 file functions to understand more how it works:

Categories