I have a slider in my page and every slider has it's own overlay descriptions and this descriptions are in the HTML format.
In my admin module there is a setting there that the user can create their own slider images with custom message using CKEditor.
And my problem is when I try to display the descriptions in the slider it's just plain HTML code.
Here's a bit of my code:
Controller Part
foreach($results as $result) {
if ($result['banner_image'] && file_exists(DIR_IMAGE . $result['banner_image'])) {
$image = $this->model_tool_image->resize($result['banner_image'], 40, 40);
$banner_image_large = HTTP_IMAGE . $result['banner_image'];
} else {
$image = $this->model_tool_image->resize('no_image.jpg', 40, 40);
}
$url = '&banner_id=' . (int)$result['banner_id'];
$this->data['banners'][] = array(
'banner_id' => $result['banner_id'],
'banner_image' => $image,
'banner_image_large' => $banner_image_large, // here's the image to be use in the slider
'code_description' => $result['banner_description'], //here's the raw HTML formatted description
'description' => strip_tags(html_entity_decode($result['banner_description'])),
'banner_link' => $result['banner_link'],
'action' => $this->url->link('project/banner_slider/update', 'token=' . $this->session->data['token'] . $url, 'SSL')
);
}
In my View
<h1>Carousel Demo</h1>
<div id="owl-demo" class="owl-carousel owl-theme">
<?php foreach($banners as $banner) { ?>
<div class="item">
<div class="textoverlay"><?php echo $banner['code_description']; ?></div> <!-- overlay the decription -->
<img src="<?php echo $banner['banner_image_large']; ?>" />
</div>
<?php } ?>
</div>
Here's some CSS
#owl-demo .item img{
display: block;
width: 100%;
height: auto;
}
.textoverlay{
position: absolute;
display:block;
}
And JS:
$('#owl-demo').owlCarousel({
autoPlay : 3000,
stopOnHover : true,
navigation : false, // Show next and prev buttons
slideSpeed : 300,
paginationSpeed : 400,
singleItem:true,
autoHeight : true,
transitionStyle:"fade"
});
surround the raw html with $.parseHTML("your html here");
Ok I solved it by using html_entity_decode() function
Related
We got this slide based on Splide, used as article's photo slider, with attached second instance that act as a thumbnail paginator.
At the moment, it doesn't take care of the height of the pics, but just use the height of the taller image, making the thumbnails remain down when a 16/9 image is displayed, leaving a big white space unused.
Even if it is an huge layout swift, we need thumbnails staying glued to the bottom of the image, sliding up or down when an image change, can we achieve this situation?
Currently, my code is:
<!-- Slideshow container -->
<section id="main-carousel" class="splide" role="group" style="margin-top: 30px" >
<div class="splide__track">
<ul class="splide__list">
<?php
$i = 0;
foreach(get_field('gallery') as $image ) {
if ($i == 0) { $active = 'active'; } else { $active = '';}
echo '<li class="splide__slide" data-splide-interval="3000">';
echo '<div class="splide__slide__container" style="max-height: fit-content>';
echo '<a href="' . $image .'" data-lightbox="image-' . ($i + 1) . '">';
echo '<img src="' . $image . '" style="width:100%" />';
echo '</a>';
echo '</div>';
echo '</li>';
$i++;
}
?>
</ul>
</div>
<br class="clear" />
</section>
<script>
var splide = new Splide( '.splide' );
splide.mount();
</script>
<section id="thumbnail-carousel" class="splide" style="margin-top: 10px; height: auto">
<div class="splide__track">
<ul class="splide__list" style="height:auto!important">
<?php
$i = 0;
foreach(get_field('gallery') as $image ) {
if ($i == 0) { $active = 'active'; } else { $active = '';}
echo '<li class="splide__slide" style="height:auto or 100%">';
echo '<img src="' . $image . '" style="width:100%; height: auto or 100%" />';
echo '</li>';
$i++;
}
?>
</ul>
</div>
</section>
<style>
.splide__list {
align-items: flex-start!important;
}
.clear { clear: both; }
</style>
<script>
document.addEventListener( 'DOMContentLoaded', function () {
var main = new Splide( '#main-carousel', {
type : 'loop',
rewind : true,
pagination: false,
arrows : false,
autoHeight: true,
autoWidth: true,
//autoplay : true,
autoStart : true,
lazyLoad: true,
perPage : 1,
perMove: 1,
autoScroll: {
speed: 1,
},
} );
var thumbnails = new Splide( '#thumbnail-carousel', {
fixedWidth : 100,
fixedHeight : 58,
gap : 8,
rewind : true,
pagination : false,
isNavigation: true,
//autoHeight: true,
breakpoints : {
600: {
fixedWidth : 60,
fixedHeight: 44,
},
},
} );
main.sync( thumbnails );
main.mount( window.splide.Extensions );
thumbnails.mount();
} );
</script>
<?php } ?>
You will need to dynamically change the slide height using the height of the next image before the carousel moves to keep the thumbnails 'glued' to the slider.
Use the Splide#on() method to listen to the ready event (to apply the first slide height) and the move event (to apply the slide height when the carousel moves).
To know which slide the carousel is moving to, use the instance property index. To change the slide height, use the property options.
var main = new Splide('#main-carousel');
main.on('ready', function() {
setHeightCarousel(0); // index = 0
})
main.mount();
main.on('move', function() {
const currentIndex = main.index;
setHeightCarousel(currentIndex);
})
And here's how setHeightCarousel(index) could look like. Note I added the class splide__img in the HTML on each <img> tag to target them.
function setHeightCarousel(index) {
const image = document.querySelectorAll('.splide__img')[index];
let imgHeight;
if (image.complete) {
imgHeight = image.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
} else {
image.addEventListener('load', function() {
imgHeight = this.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
})
}
}
Because the ready event fires before the image is loaded the function first checks whether the image is loaded, and if not adds a load event listener. A callback or promise is purposefully avoided here, but can be used to improve the code depending on the implementation.
The naturalHeight property is used to get the intrinsic height of the image, in the presumption you might want to (down)scale the image first.
Here's a working example in a JSFiddle using Splide V4.1.4.
Or view it in a snippet:
document.addEventListener('DOMContentLoaded', function() {
var main = new Splide('#main-carousel', {
type: 'fade',
rewind: true,
pagination: false,
arrows: false,
lazyLoad: 'sequential'
})
var thumbnails = new Splide('#thumbnail-carousel', {
fixedWidth: 100,
fixedHeight: 60,
gap: 10,
rewind: true,
pagination: false,
isNavigation: true,
breakpoints: {
600: {
fixedWidth: 60,
fixedHeight: 44,
},
}
})
main.on('ready', function() {
setHeightCarousel(0);
})
main.sync(thumbnails);
main.mount();
thumbnails.mount();
main.on('move', function() {
const currentIndex = main.index;
setHeightCarousel(currentIndex);
})
function setHeightCarousel(index) {
const image = document.querySelectorAll('.splide__img')[index];
let imgHeight;
if (image.complete) {
imgHeight = image.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
} else {
image.addEventListener('load', function() {
imgHeight = this.naturalHeight;
main.options = {
height: imgHeight + 'px'
}
})
}
}
})
.container {
margin: 1rem 1rem;
}
#thumbnail-carousel .splide__track .splide__list .splide__slide img {
width: 100%;
height: 100%;
object-fit: cover;
}
/* Centers the image */
/*
.splide__slide img {
width: 100%;
height: 100%;
object-fit: scale-down;
}
*/
<script src="https://cdn.jsdelivr.net/npm/#splidejs/splide#4.1.4/dist/js/splide.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/#splidejs/splide#4.1.4/dist/css/splide.min.css">
<div class="container">
<section id="main-carousel" class="splide" aria-label="Beautiful Images">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<div class="splide__slide__container">
<img data-splide-lazy="https://via.placeholder.com/250x140" alt="" class="splide__img">
</div>
</li>
<li class="splide__slide">
<div class="splide__slide__container">
<img data-splide-lazy="https://via.placeholder.com/140x250" alt="" class="splide__img">
</div>
</li>
<li class="splide__slide">
<div class="splide__slide__container">
<img data-splide-lazy="https://via.placeholder.com/250x140" alt="" class="splide__img">
</div>
</li>
</ul>
</div>
</section>
<section id="thumbnail-carousel" class="splide">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<img src="https://via.placeholder.com/250x140" alt="">
</li>
<li class="splide__slide">
<img src="https://via.placeholder.com/140x250" alt="">
</li>
<li class="splide__slide">
<img src="https://via.placeholder.com/250x140" alt="">
</li>
</ul>
</div>
</section>
</div>
A few notes.
To make lazy load work, the img element in the slide must have the data-splide-lazy attribute that indicates the path or URL to the source file.
By changing the height of the slider and therefore the position of the thumbnails you are shifting the layout. This is generally considered poor UX and can be measured using the Cumulative Layout Shift. Alternatives are to position the thumbnails on top or aside the main carousel, or by centering the 16:9 image (leaving white-space around it versus just below it).
I added the custom fields in the WordPress admin panel I added a button called Add more fields so that users can add more than one. Now my issue is, I have to display fields dynamically by clicking on the Add more fields button.
I tried the below code but when I click on the Add more fields button then I am getting the browser warning and clicking on the leave button page then the page refreshed.
What is the issue with my code?
Full code here
function woocommerce_register_2col_layout_fields() {
global $post;
// Nonce field to validate form request came from current site
wp_nonce_field( basename( __FILE__ ), 'layout' );
// Output the field
echo '<button id="addMore_layout">Add more fields</button>';
echo '<div class="create_custom_layout" id="create_custom_layout"><div class="row">';
echo '<div class="col-md-6">';
echo '<h4>Description</h4>';
//We first get the post_meta from the DB if there's any there.
$description = get_post_meta( $post->ID, 'pDescription', true );
//Second ID the field.
$description_field = 'pDescription';
//Provide the settings arguments for this specific editor in an array
$description_args = array( 'media_buttons' => false, 'textarea_rows' => 12, 'textarea_name' => 'pDescription[]',
'editor_class' => 'description-editor widefat', 'wpautop' => true );
wp_editor( $description, $description_field, $description_args );
echo '</div>';
echo '<div class="col-md-6">
<h4>Banner image</h4>
<input type="button" id="meta-image-button" class="button" value="Choose or Upload an Image" style="padding: 8px 10px; height: auto; line-height: normal;"/>
<input type="hidden" name="pimage[]" id="meta-image" class="meta_image" value="'.get_post_meta(get_the_ID(), 'pimage', true ).'" /><br />
<img style="width: 100px;height: 100px;object-fit: cover;" id="meta-image-preview" src="'.get_post_meta(get_the_ID(), 'pimage', true ).'" />
</div>
</div>
</div>
<style>
.create_custom_layout .row{display: flex;flex-wrap: wrap;}
.create_custom_layout .col-md-6 {
flex: 0 0 auto;
width: 50%;
}
</style>
<script>
jQuery("#meta-image-button").click(function() {
var send_attachment_bkp = wp.media.editor.send.attachment;
wp.media.editor.send.attachment = function(props, attachment) {
jQuery("#meta-image").val(attachment.url);
jQuery("#meta-image-preview").attr("src",attachment.url);
wp.media.editor.send.attachment = send_attachment_bkp;
}
wp.media.editor.open();
return false;
});
jQuery(function() {
jQuery("#addMore_layout").click(function(e) {
e.preventDefault();
jQuery("#create_custom_layout").append("
<div class="row"><div class="col-md-6"><h4>Description</h4>';
//We first get the post_meta from the DB if there's any there.
$description = get_post_meta( $post->ID, 'pDescription', true );
//Second ID the field.
$description_field = 'pDescription';
//Provide the settings arguments for this specific editor in an array
$description_args = array( 'media_buttons' => false, 'textarea_rows' => 12, 'textarea_name' => 'pDescription[]',
'editor_class' => 'description-editor widefat', 'wpautop' => true );
wp_editor( $description, $description_field, $description_args );
'</div>
<div class="col-md-6">
<h4>Banner image</h4>
<input type="button" id="meta-image-button" class="button" value="Choose or Upload an Image" style="padding: 8px 10px; height: auto; line-height: normal;"/>
<input type="hidden" name="pimage[]" id="meta-image" class="meta_image" value="'.get_post_meta(get_the_ID(), 'pimage', true ).'" /><br />
<img style="width: 100px;height: 100px;object-fit: cover;" id="meta-image-preview" src="'.get_post_meta(get_the_ID(), 'pimage', true ).'" />
</div>
</div>
");
});
});
</script>';
}
I have a component made by a plugin which displays a list of articles from a custom post type. Each article has the class post-id associated with. I can't override plugin's files in child theme to loop inside the template that generates the list so I need to create a function in functions.php. What I need is to replace a div inside the article with a new div styled with a custom field ( color picker ) made with advanced custom field plugin, that is associated to each article dynamically.
loop {
display: flex;
width: 100%;
}
article {
width: 200px;
height: 200px;
background: red;
margin:20px;
display:flex;
justify-content:center;
align-items:center;
}
.overlay {
width:150px;
height:150px;
}
<article class="portfolio-item post-53">
<div class="overlay" style="background-color:#000"></div>
</article>
<article class="portfolio-item post-65">
<div class="overlay" style="background-color:#000"></div>
</article>
<article class="portfolio-item post-70">
<div class="overlay" style="background-color:#000"></div>
</article>
function insert_custom_div() {
$args = array(
'meta_key' => 'new_color',
'post_type' => 'portfolio-item'
);
$posts = get_posts($args);
foreach ($posts as $post):
$color_picker_custom_field = get_field('new_color', $post->ID);
if ($color_picker_custom_field) {
?>
<script>
jQuery( document ).ready( function() {
jQuery('article').append('<div class="overlay post-<?php echo $post->ID; ?>" style="background-color:<?php echo $color_picker_custom_field; ?>"></div>');
});
</script>
<?php
}
endforeach;
}
add_action('wp_head','insert_custom_div');
You can get new color from each post to array and then pass the array to javascript with json_encode()
Here is modified fragment of your code, I'm not sure it will work since html injections to functions.php is bad practice, it's better to do it in template. Well it's just direction for thoughts:
<?php
$new_div = array();
foreach ($posts as $post):
$color_picker_custom_field = get_field('new_color', $post->ID);
$new_div[] = '<div class="overlay" style="background-color:<?php echo $color_picker_custom_field; ?>"></div>';
endforeach;
?>
<script>
jQuery( document ).ready( function() {
var new_divs = <?php echo json_encode($new_div); ?>;
jQuery( '.overlay' ).each( function(ind, el) {
jQuery(this).replaceWith(new_divs[ind]');
});
});
</script>
I was trying to change the Image inside the loop for example If I click the button that is also inside the loop it is perfectly changing the image but other data's that are in the loop was also changing to zero(0). I also add an id to a clickable button to change the image only that I clicked..
This is what iv'e tried:
HTML
<div class="ult_tabitemname current">
<div id="dashboard">
<ul class="slider-20" style="width: 5215%; position: relative; transition-duration: 0.2s; transform: translate3d(0px, 0px, 0px);">
<li aria-hidden="false" style="float: left; list-style: none; position: relative; width: 779px;"><img src="http://myurl.com/temp/wp-content/uploads/SAVED.png"><img src="http://myurl.com/temp/wp-content/uploads/1234-1.jpg" class="image-gallery"><input class="mytravel-img-id" img-cat="20" type="hidden" value="1058"></li>
<li aria-hidden="true" style="float: left; list-style: none; position: relative; width: 779px;"><img src="http://myurl.com/temp/wp-content/uploads/SAVE.png"><img src="http://myurl.com/temp/wp-content/uploads/Travel-Personality-FAQ-image-5_09-1.jpg" class="image-gallery"><input class="mytravel-img-id" img-cat="20" type="hidden" value="1059"></li>
<li aria-hidden="true" style="float: left; list-style: none; position: relative; width: 779px;">\<img src="http://myurl.com/temp/wp-content/uploads/SAVED.png"><img src="http://myurl.com/temp/wp-content/uploads/Travel-Personality-FAQ-image-3_03-1.jpg" class="image-gallery"><input class="mytravel-img-id" img-cat="20" type="hidden" value="1060"></li>
</ul>
</div>
</div>
Ajax
$('#dashboard').on("click", 'li a.save', function(){
var img_id = $('.ult_tabitemname.current li[aria-hidden=false] .mytravel-img-id').val();
var img_cat = $('.ult_tabitemname.current li[aria-hidden=false] .mytravel-img-id').attr('img-cat');
var curr_data = $('.ult_tabitemname.current li[aria-hidden=false] a.save').attr('current-data');
$.ajax({
type : "POST",
url : stats_area_load.ajax_url,
dataType : 'json',
data : {
action : 'update_save_ajax',
img_id : img_id,
img_cat : img_cat,
curr_data : curr_data
},
beforeSend: function( response ) {
//$('.ult_tabitemname.current div#dashboard').html('<div class="loading-wrap"><img src="/wp-includes/images/spinner-2x.gif"><p class="stat-loading">Loading, Please Wait...</p></div>');
},
success: function( response ) {
$('a#img-'+img_id).html('<img src="'+response.get_img_url+'" />');
}
});
});
}
PHP
add_action( 'wp_ajax_nopriv_update_save_ajax', 'update_save_ajax', 20 );
add_action( 'wp_ajax_update_save_ajax', 'update_save_ajax', 20 );
function update_save_ajax(){
$img_id = $_REQUEST['img_id'];
$img_cat = $_REQUEST['img_cat'];
$curr_data = $_REQUEST['curr_data'];
$get_curr_uid = get_current_user_id();
$url = get_bloginfo( 'url' );
$uploads = $url . '/wp-content/uploads';
$save = $uploads. '/SAVE.png';
$saved = $uploads. '/SAVED.png';
if($curr_data == 'save'){
$get_save_url = $saved;
$curr_data_save = 'saved';
}else{
$get_save_url = $save;
$curr_data_save = 'save';
}
$param = array(
'get_img_url' => $get_save_url,
'change_curr_data' => $curr_data_save,
'get_curr_img_cat' => $img_cat
);
echo json_encode($param);
die();
}
Just to make it more clear this is the sample output.. The first Image if I clicked that violet button it works perfectly and changing the Image.. In the second photo that is the other image also changing to zero.. They are on the loop..
Are you sure there is only one li[aria-hidden=false] within the entire html?
The correct approach should be like finding the unique element in order to retrieve the properties you want, by specifying the immediate parent() of the element, for e.g.
$('#dashboard').on("click", 'li > a.save', function(){
// $( this ).parent() is the immediate parent of 'a.save' which is 'li'
var img_id = $( this ).parent().find('.mytravel-img-id').val();
var img_cat = $( this ).parent().find('.mytravel-img-id').attr('img-cat');
var curr_data = $( this ).attr('current-data');
...
See also:
.val() Returns: String or Number or Array
Description: Get the current value of the first element in the set of matched elements.
.attr( attributeName ) Returns: String
Description: Get the value of an attribute for the first element in the set of matched elements.
I am using this plugin to display books, this result shows good in
IE and Chrome browser but result does not show good in Mozilla Firefox! What could be the reason ?
Good image- Chrome browser
Not good image- Mozilla Firefox
*Live demo *
Code:
<script type="text/javascript">
$(document).ready(function () {
$('#pinBoot').pinterest_grid({
no_columns: 6,
padding_x: 10,
padding_y: 10,
margin_bottom: 50,
single_column_breakpoint: 700
});
});
(function ($, window, document, undefined) {
var pluginName = 'pinterest_grid',
defaults = {
padding_x: 10,
padding_y: 10,
no_columns: 3,
margin_bottom: 50,
single_column_breakpoint: 700
},
columns,
$article,
article_width;
function Plugin(element, options) {
this.element = element;
this.options = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype.init = function () {
var self = this,
resize_finish;
$(window).resize(function () {
clearTimeout(resize_finish);
resize_finish = setTimeout(function () {
self.make_layout_change(self);
}, 11);
});
self.make_layout_change(self);
setTimeout(function () {
$(window).resize();
}, 500);
};
Plugin.prototype.calculate = function (single_column_mode) {
var self = this,
tallest = 0,
row = 0,
$container = $(this.element),
container_width = $container.width();
$article = $(this.element).children();
if (single_column_mode === true) {
article_width = $container.width() - self.options.padding_x;
} else {
article_width = ($container.width() - self.options.padding_x * self.options.no_columns) / self.options.no_columns;
}
$article.each(function () {
$(this).css('width', article_width);
});
columns = self.options.no_columns;
$article.each(function (index) {
var current_column,
left_out = 0,
top = 0,
$this = $(this),
prevAll = $this.prevAll(),
tallest = 0;
if (single_column_mode === false) {
current_column = (index % columns);
} else {
current_column = 0;
}
for (var t = 0; t < columns; t++) {
$this.removeClass('c' + t);
}
if (index % columns === 0) {
row++;
}
$this.addClass('c' + current_column);
$this.addClass('r' + row);
prevAll.each(function (index) {
if ($(this).hasClass('c' + current_column)) {
top += $(this).outerHeight() + self.options.padding_y;
}
});
if (single_column_mode === true) {
left_out = 0;
} else {
left_out = (index % columns) * (article_width + self.options.padding_x);
}
$this.css({
'left': left_out,
'top': top
});
});
this.tallest($container);
$(window).resize();
};
Plugin.prototype.tallest = function (_container) {
var column_heights = [],
largest = 0;
for (var z = 0; z < columns; z++) {
var temp_height = 0;
_container.find('.c' + z).each(function () {
temp_height += $(this).outerHeight();
});
column_heights[z] = temp_height;
}
largest = Math.max.apply(Math, column_heights);
_container.css('height', largest + (this.options.padding_y + this.options.margin_bottom));
};
Plugin.prototype.make_layout_change = function (_self) {
if ($(window).width() < _self.options.single_column_breakpoint) {
_self.calculate(true);
} else {
_self.calculate(false);
}
};
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName,
new Plugin(this, options));
}
});
}
})(jQuery, window, document);
</script>
html/php code
<div class="row">
<section id="pinBoot">
<?php
if (empty($query4)) {
echo '<p style="color:red;"> No Books To Display!</p>';
} else {
foreach ($query4 as $row) {
?>
<article class="white-panel">
<?php echo "<img src='" . base_url() . "uploads/books/$row->img1' alt='.$row->book_title.' title='$row->book_title By $row->auth_firstname $row->auth_lastname' />"; ?>
<h4>
<a class="title" href="#">
<?php echo "$row->book_title"; ?>
</a>
</h4>
<left> <img src="http://www.homequalitymark.com/filelibrary/interactive_scorecard/4_star.png" style="width:50%;height:12px;"/></left>
<p> By
<a class="link" href="" title="<?php echo $row->book_title ?>">
<?php
$afl = $row->auth_firstname . ' ' . $row->auth_lastname;
$tafln = strlen($afl);
if ($tafln >= 15) {
$afln = strip_tags($afl);
$safln = substr($afln, 0, 11);
echo "<span class='author'>$safln ...</span>";
} else {
echo "<span title='$row->auth_firstname $row->auth_lastname' class='author'> $row->auth_firstname $row->auth_lastname</span>";
}
?>
</a> <br/>
Number of Pages:<?php echo $row->pages; ?>
</p>
Rent
Add to Wishlist
</p>
</article>
<?php
}
}
?>
</section>
<hr>
<div id="divId">
</div>
</div>
Edit: I added the description.
The CSS "row" and "pinBoot" selector rules used in the example are not given.
<div class="row">
<section id="pinBoot">
I've used and tried the original CSS selectors. The problem may be with the "row" and "pinBoot" selectors.
<div class="container marketing">
<section id="blog-landing">
It will also work when you add "container" to the "row" class.
<div class = "container"> or <div class = "row container">
Sorry English is not good, I can't explain more. I hope I can tell.
Please test, example. Code create php file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Pinterest Grid Plugin Example</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style>
body {
background: #E9E9E9;
}
#blog-landing {
margin-top: 81px;
position: relative;
max-width: 100%;
width: 100%;
}
img {
width: 100%;
max-width: 100%;
height: auto;
}
.white-panel {
position: absolute;
background: white;
box-shadow: 0px 1px 2px rgba(0,0,0,0.3);
padding: 10px;
}
.white-panel h1 {
font-size: 1em;
}
.white-panel h1 a {
color: #A92733;
}
.white-panel:hover {
box-shadow: 1px 1px 10px rgba(0,0,0,0.5);
margin-top: -5px;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
</style>
<link href="http://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css">
</head>
<!-- NAVBAR
================================================== -->
<body>
<?php
$query4 = array(
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
),
array(
'img1' => 'http://www.mediademon.com/wp-content/uploads/2014/04/food-drink-expo.png',
'book_title' => 'Is your website converting visits into sales?',
'auth_firstname' => 'Roberto',
'auth_lastname' => 'Doleto',
'pages' => '23',
'book_id' => '2'
)
);
$query4 = json_decode(json_encode($query4));
?>
<h1 style="margin-top:150px" align="center">jQuery Pinterest Grid Plugin Example</h1>
<div class="container marketing">
<section id="blog-landing">
<?php foreach ($query4 as $row) { ?>
<article class="white-panel">
<?php echo "<img src='{$row->img1}' alt='.{$row->book_title}.' title='{$row->book_title} By {$row->auth_firstname} {$row->auth_lastname}' />"; ?>
<h4><?php echo "$row->book_title"; ?></h4>
<p>
<a class="link" href="" title="<?php echo $row->book_title ?>">
<?php
$afl = $row->auth_firstname . ' ' . $row->auth_lastname;
$tafln = strlen($afl);
if ($tafln >= 15) {
$afln = strip_tags($afl);
$safln = substr($afln, 0, 11);
echo "<span class='author'>$safln ...</span>";
} else {
echo "<span title='{$row->auth_firstname} {$row->auth_lastname}' class='author'> {$row->auth_firstname} {$row->auth_lastname}</span>";
}
?>
</a> <br/>
Number of Pages:<?php echo $row->pages; ?>
</p>
<p>
Rent
Add to Wishlist
</p>
</article>
<?php } ?>
</section>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://www.jqueryscript.net/demo/Simple-jQuery-Plugin-To-Create-Pinterest-Style-Grid-Layout-Pinterest-Grid/pinterest_grid.js"></script>
<script>
$(document).ready(function() {
$('#blog-landing').pinterest_grid({
no_columns: 4,
padding_x: 10,
padding_y: 10,
margin_bottom: 50,
single_column_breakpoint: 700
});
});
</script>
</body>
</html>
Have you tried adding some console.log()'s to all the JS handlers to ensure they are firing as expected in all browsers.
As your code is dependant on your data set it is difficult to test. Have you considered using just bootstrap. this will result in a more grid like layout. note bootstrap col class on the article
<?php
if (empty($query4)) {
echo '<p style="color:red;">No Books To Display!</p>';
} else {
var counter =0;
foreach ($query4 as $row) {
if (counter % 6 == 0) {
echo "<div class='clearfix'></div>";
}
counter ++;
?>
<article class="white-panel col-xs-2"><!-- note bootstrap col class 2 -->
<?php echo "<img src='" . base_url() . "uploads/books/$row->img1' alt='.$row->book_title.' title='$row->book_title By $row->auth_firstname $row->auth_lastname' />"; ?>
<h4>
<a class="title" href="#">
<?php echo "$row->book_title"; ?>
</a>
</h4>
<left> <img src="http://www.homequalitymark.com/filelibrary/interactive_scorecard/4_star.png" style="width:50%;height:12px;"/></left>
<p> By
<a class="link" href="" title="<?php echo $row->book_title ?>">
<?php
$afl = $row->auth_firstname . ' ' . $row->auth_lastname;
$tafln = strlen($afl);
if ($tafln >= 15) {
$afln = strip_tags($afl);
$safln = substr($afln, 0, 11);
echo "<span class='author'>$safln ...</span>";
} else {
echo "<span title='$row->auth_firstname $row->auth_lastname' class='author'> $row->auth_firstname $row->auth_lastname</span>";
}
?>
</a>
<br/>
Number of Pages:<?php echo $row->pages; ?>
</p>
Rent
Add to Wishlist
</p>
</article>
<?php
}
}
?>
also consider using external css instead of <br/>, inline css and 's