<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jared Atchison<title>&#187; jcarousel</title>
</title>
	<atom:link href="http://www.jaredatchison.com/tag/jcarousel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jaredatchison.com</link>
	<description>Websites. Wordpress. Genesis.</description>
	<lastBuildDate>Tue, 07 Sep 2010 03:09:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rotating banners in WordPress with jQuery</title>
		<link>http://www.jaredatchison.com/2009/11/12/rotating-banners-in-wordpress-with-jquery/</link>
		<comments>http://www.jaredatchison.com/2009/11/12/rotating-banners-in-wordpress-with-jquery/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 18:39:44 +0000</pubDate>
		<dc:creator>j-atchison</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Banners]]></category>
		<category><![CDATA[jcarousel]]></category>

		<guid isPermaLink="false">http://jaredatchison.com/?p=104</guid>
		<description><![CDATA[Recently I had a project that needed to have a rotating banner on the main page. Most rotating banners out there are connected to feature posts or articles. WooThemes and some of Matt Brett&#8217;s projects often use this method. This wasn&#8217;t going to cut it for me. I needed to have rotating banners that were [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had a project that needed to have a rotating banner on the main page. Most rotating banners out there are connected to feature posts or articles. <a href="http://woothemes.com">WooThemes</a> and some of <a href="http://mattbrett.com">Matt Brett&#8217;s</a> projects often use this method.</p>
<p>This wasn&#8217;t going to cut it for me. I needed to have rotating banners that were not associated to any posts, could link off site, be updated/maintained by the client, and preferably <em>not use any custom field voodoo</em>. The last thing I wanted to do was use a post category since it would be major over kill.</p>
<p>So I came up with a solution that fit all my requirements above and works great. Figured I would share what I did in case anyone else needs a similar solution.</p>
<p>The rotating banners were accomplished using:</p>
<ul>
<li>jQuery</li>
<li><a href="http://sorgalla.com/jcarousel/">jQuery Carousel plugin</a></li>
<li>WordPress Link Manger</li>
</ul>
<p>Let&#8217;s get started here.</p>
<h4>Step 1: setup a link category</h4>
<p>When you&#8217;re logged into the WP admin panel, click on <em>Links</em> on the left (under <em>Media</em>, above <em>Pages</em>). The <em>Links</em> section will expand and now we need to create a Link Category.</p>
<div id="attachment_105" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.jaredatchison.com/files/2009/11/add_link_cat.png" rel="shadowbox[post-104];player=img;"><img class="size-large wp-image-105" src="http://www.jaredatchison.com/files/2009/11/add_link_cat-600x409.png" alt="add_link_cat" width="600" height="409" /></a><p class="wp-caption-text">Add your Banner category</p></div>
<p>After you have added your Banner category (or whatever you decide to name it) you want to find the ID for that category. There are 2 ways you can do this. First, place you cursor over the category and look in browser status bar.</p>
<p><a href="http://www.jaredatchison.com/files/2009/11/find_cat.jpg" rel="shadowbox[post-104];player=img;"><img class="aligncenter size-large wp-image-106" src="http://www.jaredatchison.com/files/2009/11/find_cat-600x418.jpg" alt="find_cat" width="600" height="418" /></a></p>
<p>The second option is to use Sivel&#8217;s <a href="http://wordpress.org/extend/plugins/simply-show-ids/">Simply Show IDs plugin </a>which will tell you the ID. Either way, just make sure you note what the ID is for your category since we will need it later.</p>
<h4>Step 2: add some banners</h4>
<p>Now we will add some links to the category. Click Add New under Links.</p>
<p><a href="http://www.jaredatchison.com/files/2009/11/add_link.jpg" rel="shadowbox[post-104];player=img;"><img class="aligncenter size-large wp-image-107" src="http://www.jaredatchison.com/files/2009/11/add_link-528x600.jpg" alt="add_link" width="528" height="600" /></a></p>
<p>The name and description is for your reference and will not be shown or used. Make sure you place the link in the category you created. Lastly you will need to put the location of the image in the<em> Image Address</em> field. The easiest way is to upload your banners using the WordPress Media manager. If you go that route your image location will be something similar to http://yoursite.com/wp-contents/uploads/11/09/banner.jpg.</p>
<h4>Step 4: downloading  and moving jQuery Carousel</h4>
<p>Now that we have the banner category created and some links/images in the category we need to get things setup behind the scenes.</p>
<p>First, download <a href="http://sorgalla.com/jcarousel/">jQuery Carousel</a>.</p>
<p>Secondly, unzip the files. You will see a bunch of files, most of which we won&#8217;t need.</p>
<p>Open up your theme folder (/wp-contents/themes/yourtheme/) and create a folder inside called <strong>js</strong>.</p>
<p>Now we need to move <strong>jquery.jcarousel.pack.js</strong> <em>or</em> jquery.jcarousel.js (look in the /libs/) to this folder. The path should be similar to <strong>/wp-contents/themes/yourtheme/js/jquery.jcarousel.pack.js</strong></p>
<p>Note: It is up to you which version of jCarousel you use. I prefer the packed version since it is smaller and we will not need to do any editing.</p>
<p>After the jCarousel javascript file has been moved we need to move over the CSS. Open jquery.jcarousel.css, copy the contents, and paste it into your theme&#8217;s style.css.</p>
<p>So to recap, you should have:<br />
/wp-contents/themes/yourtheme/js/jquery.jcarousel.pack.js<br />
/wp-contents/themes/yourtheme/style.css (should contain the CSS from jquery.jcarousel.css)</p>
<h4>Step 5: setting up jCarousel and jQuery</h4>
<p>Once you have added the necessary jCarousel CSS to your theme&#8217;s style.css you will need to edit it to meet the dimensions of your banner.</p>
<pre class="brush: css;">
/* @group jcarousel */

.jcarousel-banners {
 border: 1px solid #cfcfcf;
 margin:0 0 30px 0;
}

.jcarousel-container {
 position: relative;
}

.jcarousel-clip {
 z-index: 2;
 padding: 0;
 margin: 0;
 overflow: hidden;
 position: relative;
}

.jcarousel-list {
 z-index: 1;
 overflow: hidden;
 position: relative;
 top: 0;
 left: 0;
 margin: 0;
 padding: 0;
}

.jcarousel-list li,
.jcarousel-item {
 float: left;
 list-style: none;
 /* We set the width/height explicitly. No width/height causes infinite loops. */
 width: 578px;
 height: 130px;
}

/**
 * The buttons are added dynamically by jCarousel before
 * the &lt;ul&gt; list (inside the &lt;div&gt; described above) and
 * have the classnames &quot;jcarousel-next&quot; and &quot;jcarousel-prev&quot;.
 */
.jcarousel-next {
 display: none;
}
.jcarousel-prev {
 display: none;
}

.jcarousel-banners .jcarousel-list li,
.jcarousel-banners .jcarousel-item {
 position: relative;
 float: left;
 list-style: none;
 width: 578px;
 height: 130px;
}

.jcarousel-banners .jcarousel-container-horizontal {
 width: 578px;
}

.jcarousel-banners .jcarousel-clip-horizontal {
 width: 578px;
 height: 130px;
}

.jcarousel-banners .jcarousel-item {
 width: 578px;
 height: 130px;
}
</pre>
<p>Above is what the CSS looks like for my website. The size of the banners is 578x130px. Change this to the size of your banners. You might need to do some further tweaking later.</p>
<p>Now the CSS is done and jCarousel is in place we need to tell WordPress to use jQuery and jCarousel when it loads a page.</p>
<p>Open up <strong>functions.php</strong> inside your theme directory. You may have to create it if your theme does not have one. Now add this:</p>
<pre class="brush: php;">
if (!is_admin()) {
wp_enqueue_script('jquery');
wp_enqueue_script('jcarousel','/wp-content/themes/yourtheme/js/jquery.jcarousel.js',false,false);
}
</pre>
<p>WordPress includes many scripts out of the box, one of them being jQuery, so there is no need for us to download it. The code snippet tells WordPress &#8211; as long as we are not in the admin panel &#8211; to load jQuery and the jCarousel script.</p>
<h4>Step 6: finishing things up on the front end</h4>
<p>Your banners have been created, the files have been moved, and WordPress now knows to use jQuery and jCarousel when a page loads &#8211; almost done!</p>
<p>The last thing we need to do is add the code to grab the banners and make them work.</p>
<p>Open up  <strong>index.php</strong> or <strong>home.php</strong> (the location you want to place your banners)  in your theme directory and use this snippet:</p>
<pre class="brush: php;">
&lt;div id=&quot;banners&quot;&gt;
&lt;ul&gt;
&lt;?php wp_list_bookmarks( 'categorize=0&amp;category=49&lt;&amp;title_li=&amp;before=&lt;li&gt;&amp;after=&lt;/li&gt;&amp;show_images=1&amp;show_description=0' ); ?&gt;
&lt;/ul&gt;
 &lt;/div&gt;
</pre>
<p>This snippet will grab links you created earlier and only show the images. Make sure you change category=49 to your category ID.</p>
<p>Lastly, open <strong>header.php</strong> in your theme directory. Place the code snippet below in between the &lt;head&gt; &lt;/head&gt; tags &#8211; usually right after you see wp_head();</p>
<pre class="brush: jscript;">
jQuery(document).ready(function($) {
$('#banners').jcarousel({
scroll: 1,
auto: 4,
wrap: 'last',
animation: 'slow',
buttonNextHTML: null,
buttonPrevHTML: null
});
});
</pre>
<p>The jQuery that comes with WordPress runs in non conflict mode, which is why do not use the typical document ready call. jCarousel is very configurable, so I suggest you check out all the <a href="http://sorgalla.com/projects/jcarousel/#Configuration">different options</a> and make sure your settings are set for the functionality you desire.</p>
<h3>Step 7: Profit.</h3>
<p><strong><em>That&#8217;s it!</em></strong> If you followed all the steps right you should have a rotating banner on your site.</p>
<p>I found this to be a better solution that any of the plugins I found. We didn&#8217;t have to do anything crazy, use posts, or write any plugins. Normally I would provide a demo of this in action but I have a feeling the client I did this for would rather not be mentioned.</p>
<p>If you have an questions or problems, feel free to leave a comment.</p>
<p>If you do expereince problems, a few things to double check/tweak:</p>
<ul>
<li>view your source to make sure WP is calling jQuery and jCarousel</li>
<li>check to make sure you have the correct category ID</li>
<li>modify the CSS if things don&#8217;t render correctly</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jaredatchison.com/2009/11/12/rotating-banners-in-wordpress-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
