





















































Over 50 incredibly effective and quick recipes for building modern eye-catching OpenCart templates
In this recipe, we will download jQuery and jCarousel and also install them into our store. By default, OpenCart comes with jQuery installed.
Carousels have become a popular means to display products. There are many different types of carousels. But, we will use jCarousel for this recipe. You can use your favourite one.
We need jQuery for our dynamic content throughout the site. jQuery is added by default with OpenCart. But here, we will also see how to download it and install it. We will download and install jQuery and jCarousel. First, we will go to the sites from where we can download them. If jQuery is not present in your site, you can download it from http://docs.jquery.com/Downloading_jquery. We will download the latest jQuery JavaScript file.
First, we need to download the required files to use jCarousel. We need the jQuery JavaScript file and jCarousel JavaScript and css files. To check whether our site is jQuery-enabled or not, we can use web developer Firefox addons.
Click on the information tab of Web Developer:
It will display many sub-menus. Every sub-menu has its own importance. We select View JavaScript.
Then, a new tab will open containing all the JavaScripts for the web page in it. You can contract or expand the links. If our store already has jQuery, then we can find it in this page. Otherwise, it won't be in this page or it will show a 404 error.
Since our store is jQuery-enabled by default, we don't need to install jQuery. We have shown the installation of jQuery so that you can have full control of the process. There are several releases available to download. After downloading jQuery, we will place it under the catalogviewJavascriptjQuery folder.
Now, we will download jCarousel. We can download it from http://sorgalla.com/projects/jCarousel/.
Then, extract the compressed file. There will be many files in the extracted folder. Under the lib folder, we have an uncompressed and minified version of jCarousel. We create a folder named jCarousel under catalogviewiavascriptjquery. Then, in the jCarousel folder, create another folder named js. We will place any one of the two files under catalogviewjavascriptjqueryjcarouseljs.
And bring the skins folder under the catalogviewjavascriptjqueryjcarousel.
We have installed jQuery and jCarousel in the previous recipe. Here, we will see how we can display products with jCarousel. In this recipe, we are going use jCarousel for the latest products, but you can use it for other modules as well.
First, we will open the header.tpl file under catalogviewthemeshoptemplatecommon. If we don't have jQuery in our site, then we need to add it here. See the following code block:
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery-1.3.2.min.js"></script>
We will follow the steps below for jCarousel addition to our store:
<script type="text/javascript" src="catalog/view/javascript/jquery/jcarousel/lib/jquery.jcarousel.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/javascript/jquery/jcarousel/skins/tango/skin.css" />
<table class="list"> //... </table>
<ul id="latestcarousel" class="jCarousel-skin-tango"> //... </ul>
<tr> //... </tr>
<td style="width: 25%;"><?php if (isset($products[$j])) { ?> //... <?php } ?></td>
<li> //... </li>
<script type="text/javascript"> jQuery(document).ready(function() { jQuery('#latestcarousel').jcarouseljcarousel(); }); </script>
If we see our changes in the browser, then we will find it as:
.jcarousel-skin-tango .jcarousel-container-horizontal {
width: 245px;
padding: 20px 40px;
}
To the following code:
.jcarousel-skin-tango .jcarousel-container-horizontal {
width: auto;
padding: 20px 40px;
}
Again, if we are going to use jCarousel in some other places as well, it is not smart to change the skin.css. Instead we can override it in our theme-css for a specific region. For example, #content .middle .jcarousel-skin-tango .jcarousel-container-horizontal. Here, we have just shown you one instance of jCarousel usage.
We changed the width to auto. So, in the browser, the carousel will be like this:
.jcarousel-skin-tango .jcarousel-clip-horizontal {
width: auto;
height: 75px;
}
Our height for the carousel is small. Let's change the height of it. We change the height to 200px:
.jcarousel-skin-tango .jcarousel-clip-horizontal { width: auto; height: 200px; }
.jcarousel-skin-tango .jcarousel-item {
width: 75px;
height: 200px;
}
.jcarousel-skin-tango .jcarousel-item-horizontal {
margin-left: 0;
margin-right: 50px;
}
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#latestcarousel').jcarousel({
scroll: 1,
visible: 3,
auto: 3,
rtl: true,
wrap: 'circular'
});
});
</script>