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
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 Want autoload more data on page scroll so I tried following:
Index.php
<!DOCTYPE html>
<html>
<head>
<title>Auto Load More Data on Page Scroll with Jquery & PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2 align="center">Auto Load More Data on Page Scroll with Jquery & PHP</a></h2>
<input type="text" name="search_text" id="search_text" value="para" placeholder="Search by Name" class="form-control" />
<br />
<div id="load_data"></div>
<div id="load_data_message"></div>
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</body>
</html>
<script>
$(document).ready(function(){
var limit = 7;
var start = 0;
var action = 'inactive';
function load_country_data(limit, start,query)
{
$.ajax({
url:"fetch.php",
method:"POST",
data:{limit:limit, start:start, query:query},
cache:false,
success:function(data)
{
$('#load_data').append(data);
if(data == '')
{
$('#load_data_message').html("<button type='button' class='btn btn-info'>No Data Found</button>");
action = 'active';
}
else
{
$('#load_data_message').html("<button type='button' class='btn btn-warning'>Please Wait....</button>");
action = "inactive";
}
}
});
}
if(action == 'inactive')
{
action = 'active';
load_country_data(limit, start);
}
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
{
action = 'active';
start = start + limit;
setTimeout(function(){
load_country_data(limit, start);
}, 1000);
}
});
});
</script>
above code sends post request to fetch.php with search query and skip and limit.
and fetch.php got data sends by index.php and process it and sends back the output back to index page.
<?php
error_reporting(0);
require 'vendor/autoload.php';
$output = '';
$search = '';
if(isset($_POST["limit"],$_POST["start"],$_POST["query"]))
{
$search = $_POST["query"];
$limit = $_POST["limit"];
$skip = $_POST["start"];
echo "Searching for ";
echo $search;
echo "<BR>";
$output .= '<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>Name</th>
<th>basics</th>
<th>Manufacturer</th>
<th>Get full Details</th>
</tr>';
echo $output;
$client = new MongoDB\Client();
$c1 = $client->testdb->{'data360'};
$queryString = ".*".$search.".*";
$query = array(
'$or' => array(
array(
'name' => array (
'$regex' => new \MongoDB\BSON\Regex($queryString),
'$options' => 'i'
)
),
array(
'pre.basics' => array (
'$regex' => new \MongoDB\BSON\Regex($queryString),
'$options' => 'i'
)
),
array(
'Pre.Manufacturer' => array (
'$regex' => new \MongoDB\BSON\Regex($queryString),
'$options' => 'i'
)
),
)
);
$options = [
'skip' => $start,
'limit' => $limit
];
$cursor = $c1->find($query,$options);
//$results = $c->aggregate($ops);
//var_dump($cursor);
foreach ($cursor as $document) {
$output = '
<tr>
<td>'.$document['name'].'</td>
<td>'.$document['Pre']['basics'].'</td>
<td>'.$document['Pres']['Manufacturer'].'</td>
</tr>
';
echo $output;
}
}
else
{
// the array of product criteria
}
?>
where it goes wrong? and why its not working..? Give me solution to this problem...
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
I am using this code to create a dynamic lost of CMS pages in Magento, it;'s working fine but I'd love to sort it alphabetically and I cannot work out how to do it
<?php
$cmsPages = Mage::getModel('cms/page')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active',1)
->addFieldToFilter('identifier', array(
array(
'nin' => array(
'home',
'no-route',
'enable-cookies',
'thank-you',
'home-demo',
'empty'
)
)
)
);
?>
<style type="text/css">
#cms-navigation a.active { color: red; }
</style>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
jQuery('#cms-navigation a').each(function(){
if(urlRegExp.test(this.href.replace(/\/$/,''))){
jQuery(this).addClass('active');
}
});
});
</script>
<div class="block">
<div class="block-title">
<strong><span>CMS Navigation</span></strong>
</div>
<div class="block-content">
<ul id="cms-navigation" style="padding: 10px;">
<?php
foreach($cmsPages as $_cms):
$page = $_cms->getData();
//sort ($_cms->getData('title'));
?>
<li><?php echo $_cms['title']; ?></li>
<?php
endforeach;
?>
</ul>
</div>
</div>
You can see where I've commented out my attempt at sorting, I've tried just about everything I can think of but now I'm a bit stumped.
Many thanks to anyone who can help
You can use the setOrder() method inherited from the Varien_Data_Collection_Db superclass
$cmsPages = Mage::getModel('cms/page')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active',1)
->addFieldToFilter('identifier', array(
array(
'nin' => array(
'home',
'no-route',
'enable-cookies',
'thank-you',
'home-demo',
'empty'
)
)
)
)
->setOrder('title','ASC');
I have following array:
$firstlevel=array(“numbers”,”vowels”,”animals”,”birds”);
$numbers=array(“one”,”two”,”three”);
$vowels= array (“a”,”e”,”i”,,”o”,”u”);
$animals=array(“lion”,”tiger”,”dog”,”wolf”,”horse”,”Zebra”);
$birds=array(“parrot”,”sparrow”,”crow”);
I need tree menu like below:(ONLY BY USING PHP)
+ numbers
+ vowels
+ animals
+ birds
Reset button
When clicking it expands like following:
+ Fruits
- Vegetables
+ Drumstick
+ Lady’s finger
+ Animals
+ Birds
The same format should be retain once we click on the other first level item its
corresponding child nodes to be in expanded.
This is For pure css, js and html code. For php refer next section.
$(document).ready(function(){
$('.child').hide();
});
$( "a" ).click(function() {
Show(this);
});
function Show(obj)
{
var ObjId = obj.id;
var Obj = ObjId.split('-');
var id = Obj[0];
var symb = $('#'+id+'-symbol').html();
if(symb.trim() == "+")
{
$('#'+id).show(1000);
$('#'+id+'-symbol').html("- ");
}
else
{
$('#'+id).hide(1000);
$('#'+id+'-symbol').html("+ ");
}
}
ul {
list-style: none;
margin-left:10px;
}
ul>li{
margin-left:15px;
padding-top:10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<a id='fruit-a' style='text-decoration:none; color:black;' href='#'>
<span id='fruit-symbol'>+ </span>
Fruit
</a>
<ul class='child' id='fruit'>
<li>* numbers</li>
<li>* vowels</li>
<li>* animals</li>
<li>* birds</li>
</ul>
</li>
</ul>
You can do it like this with php.
<html>
<head>
<style>
ul {
list-style: none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.child').hide();
});
function Show(id)
{
var symb = $('#'+id+'-symbol').html();
if(symb.trim() == "+")
{
$('#'+id).show(1000);
$('#'+id+'-symbol').html("- ");
}
else
{
$('#'+id).hide(1000);
$('#'+id+'-symbol').html("+ ");
}
}
</script>
</head>
<body>
<?php
$firstlevel=array("numbers","vowels","animals","birds");
$numbers=array("one","two","three");
$vowels= array ("a","e","i","o","u");
$animals=array("lion","tiger","dog","wolf","horse","Zebra");
$birds=array("parrot","sparrow","crow");
$AllArray = ["firstlevel", "numbers", "vowels", "animals", "birds"];
echo "<ul>";
foreach($AllArray as $a)
{
echo "<li><a onclick=\"Show('".$a."')\" style='text-decoration:none; color:black;' href='#'><span id='".$a."-symbol'>+ </span>".$a."</a><ul class='child' id='".$a."'>";
foreach($$a as $id=>$val)
{
echo "<li>* ".$val."</li>";
}
echo "</ul></li>";
}
echo "</ul>";
?>
</body>
</html>
You can see result through this link https://www.tehplayground.com/5SHAWKeEcsm5O5Ww
use jquery with php u will get i did same thing try this......
include this first
<div class="menu_list" id="secondpane"> <!--Code for menu starts here-->
<p class="menu_head">Data Warehousing</p>
<div class="menu_body">
Teradata Online training
Informatica Online training
Cognos Online training
</div>
<p class="menu_head">SAP</p>
<div class="menu_body">
SAP BO
SAP ABAP
SAP BI/BW
SAP FICO
SAP HR
</div>
<p class="menu_head">ORACLE</p>
<div class="menu_body">
ORACLE DBA
ORACLE 11g
</div>
<p class="menu_head">SQL</p>
<div class="menu_body">
SQL DBA
</div>
<p class="menu_head">JAVA</p>
<div class="menu_body">
Core JAVA
Advanced JAVA
</div>
<p class="menu_head">SAS</p>
<div class="menu_body">
SAS BI
SAS CDM
</div>
<p class="menu_head">Testing Tools</p>
<div class="menu_body">
Manual Testing+QTP Training
ETL Testing
SELENIUM Training
</div>
<p class="menu_head">Android Training</p>
<div class="menu_body">
Android Course
</div>
<p class="menu_head">Sharepoint Training</p>
<p class="menu_head">.NET Training</p>
<div class="menu_body">
ASP .NET Training
C# Training
</div>
</div>
add these styles
#charset "utf-8";
/* CSS Document */
body {
margin: 10px auto;
font: 105%/140% Verdana,Arial, Helvetica, sans-serif;
}
.menu_list {
width:250px;
}
.menu_head {
padding: 5px 10px;
cursor: pointer;
position: relative;
margin:1px;
font-weight:bold;
background:#83C7DA url(left.png) center right no-repeat;
font-size:15px;
color:black;
border-radius:5px;
}
.menu_body {
display:none;
}
.menu_body a{
display:block;
color:#C00;
background-color:#EFEFEF;
padding-left:10px;
font-weight:bold;
text-decoration:none;
}
.menu_body a:hover{
color: #000000;
text-decoration:underline;
}
integrate jQuery.js library then only it will work.....
<script type="text/javascript" language="javascript" src="jquery.js"></script>
<script type="text/javascript">
<!--//---------------------------------+
// Developed by Roshan Bhattarai
// Visit http://roshanbh.com.np for this script and more.
// This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
//slides the element with class "menu_body" when mouse is over the paragraph
$("#secondpane p.menu_head").mouseover(function()
{
$(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
$(this).siblings().css({backgroundImage:"url(left.png)"});
});
});
</script>
First of all, you need to create a table like this:
CREATE TABLE IF NOT EXISTS `menus` (
`cid` int(10) NOT NULL,
`name` varchar(20) NOT NULL,
`parent_cat` int(10) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `menus` (`cid`, `name`, `parent_cat`) VALUES
(1, 'numbers', 0),
(2, 'vowels', 0),
(3, 'one', 7),
(4, 'two', 7),
(5, 'a', 2),
(6, 'e', 2),
(7, 'ones', 1),
(8, 'tens', 1),
(9, 'ten', 8),
(10, 'twenty', 8);
Download this plug-in
and here is my php code for creating expand and collapse menu:
<?php
$viewsql = "SELECT * FROM menus";
$viewsqlres=mysql_query($viewsql);
while ( $viewsqlrow = mysql_fetch_array($viewsqlres)) {
$viewarray[$viewsqlrow['cid']] = array('cid'=>$viewsqlrow['cid'],'name' => $viewsqlrow['name'],'parent_cat' => $viewsqlrow['parent_cat']);
}
function view_generate_menu($parent_cat_view) //recursive function that prints category as a nested html unorderd list
{
$has_childs_view = false;
////this prevents printing 'ul' if we don't have subcategory for this category
global $viewarray;
////use global array variable instead of a local variable to lower stack memory requierment
foreach($viewarray as $key => $value_view) {
if ($value_view['parent_cat'] == $parent_cat_view) {
//if this is the first child print '<ul>'
if ($has_childs_view === false) {
//don't print '<ul>' multiple times
$has_childs_view = true;
?>
<ul id="tree">
<?php } ?>
<li><?php echo $value_view['name']; ?>
<?php
view_generate_menu($key);
////call function again to generate nested list for subcategory belonging to this category
echo '</li>';
}
}
if ($has_childs_view === true) echo '</ul>';
}
view_generate_menu(0);
?>
some styling:
<style>
#tree li {
list-style: none outside none;}
</style>