<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Metaphor Creations</title>
	
	<link>http://www.metaphorcreations.com</link>
	<description />
	<lastBuildDate>Tue, 14 Feb 2012 17:04:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/metaphorcreations" /><feedburner:info uri="metaphorcreations" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Nivo Slider and Custom Links</title>
		<link>http://feedproxy.google.com/~r/metaphorcreations/~3/x93lCnJd8Dg/</link>
		<comments>http://www.metaphorcreations.com/nivo-slider-and-custom-links/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 02:10:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Nivo Slider]]></category>

		<guid isPermaLink="false">http://www.metaphorcreations.com/?p=157</guid>
		<description><![CDATA[Recently I was working on a project that needed a couple image sliders built into it so I hopped on the web to grab a copy of the Nivo Slider jQuery plugin. I&#8217;ve used Nivo Slider for a bunch of other projects, and it&#8217;s a great tool to use if you want to implement a [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a project that needed a couple image sliders built into it so I hopped on the web to grab a copy of the <a href="http://nivo.dev7studios.com/" target="_blank">Nivo Slider</a> jQuery plugin. I&#8217;ve used Nivo Slider for a bunch of other projects, and it&#8217;s a great tool to use if you want to implement a slick image slider into your site.</p>
<p>Like any other jQuery plugin (or any product in general), you need to sit down and figure out the different options and limitations of it. Nivo Slider is great for adding an image slider with navigation controls and thumbnails, but for this project I needed to be able to navigate to specific images with a custom navigation menu&#8230; hmmmm. There didn&#8217;t seem to be any way to do that. So, I set out on Google to do some research (as any good web developer should do) and there didn&#8217;t seem to be any good advice on how to do this. I did find one post that had some instructions on modifying the Nivo source code&#8230; but, I try to stay away from that. There&#8217;s nothing worse than modifying the source code of someone else&#8217;s Open Source code and months later accidentally overwriting it with an updated version! Even just having to search through the updated code to update the file again is a pain. So, after trying to find a quick solution online, I sat down and figured out a pretty darn good solution that uses the Nivo Slider&#8217;s built-in event listeners and variables.</p>
<h3>The Quick Solution:</h3>
<p>Use the Nivo Slider&#8217;s &#8220;afterLoad&#8221; function along with Nivo Slider&#8217;s &#8220;data&#8221; variable, along with the Nivo Slider&#8217;s &#8220;next&#8221; navigation button. In this example the custom menu is in the same order as the Nivo Slider&#8217;s images. This allows jQuery to find the menu item&#8217;s index value, which will correlate with the correct Nivo Slider item.</p>
<pre class="brush: php; title: ; notranslate">

jQuery( '#slider' ).nivoSlider( {

	afterLoad: function(){

		jQuery( '.nivo-menu-container ul li a' ).click( function( e ) {

			// Prevent default

			e.preventDefault();

			var $li = jQuery( this ).parent();

			var pos = $li.parent().children().index( $li );

			jQuery( '#slider' ).data( 'nivo:vars' ).currentSlide = (pos-1);

			jQuery( '.nivo-nextNav' ).trigger('click');

		} );

	}

} );
</pre>
<h3>So, what&#8217;s going on here?</h3>
<p>After the Nivo Slider has loaded, it trigger&#8217;s an &#8220;afterLoad&#8221; function. Within the &#8220;afterLoad&#8221; event listener, I added a click listener to my custom menu &lt;a&gt; tags:</p>
<pre class="brush: php; title: ; notranslate">

jQuery( '.nivo-menu-container ul li a' ).click( function( e ) {

} );
</pre>
<p>Within this function, I first make sure to cancel out any default behavior of the &lt;a&gt; tag:</p>
<pre class="brush: php; title: ; notranslate">

// Prevent default

e.preventDefault();
</pre>
<p>I then find the index value of the link:</p>
<pre class="brush: php; title: ; notranslate">

var $li = jQuery( this ).parent();

var pos = $li.parent().children().index( $li );
</pre>
<p>The next step is to manually set the currentSlide variable of the Nivo Slider. Note that I set the position to be 1 before the index number we want:</p>
<pre class="brush: php; title: ; notranslate">

jQuery( '#slider' ).data( 'nivo:vars' ).currentSlide = (pos-1);
</pre>
<p>The final step is to trigger the Nivo Slider&#8217;s next button, as if the user clicked it. Since we set the currentSlide variable 1 number back this click will now tell Nivo Slider to load the image we want!:</p>
<pre class="brush: php; title: ; notranslate">

jQuery( '.nivo-nextNav' ).trigger('click');
</pre>
<h3>One last thing:</h3>
<p>I did notice that the Nivo Slider does take a little time to load&#8230; it&#8217;s not much, but depending on your image sizes it does allow the user to click your custom menu before the &#8220;afterLoad&#8221; function has triggered. This allow the &lt;a&gt; take to actually try to link somewhere. So, to counteract this I did add another click listener outside of the NivoSlider code that prevents the default click action:</p>
<pre class="brush: php; title: ; notranslate">

jQuery( '.nivo-menu-container ul li a' ).click( function( e ) {

	e.preventDefault();

} );
</pre>
<h3>Extra Stuff:</h3>
<p>I also needed to highlight the custom menu item of the current Nivo Slider image. To do this I used the built-in &#8220;beforeChange&#8221; event, and used a &#8220;selected&#8221; class on the list items to reference in my CSS file.</p>
<pre class="brush: php; title: ; notranslate">

beforeChange: function(){

 var currentSlide = jQuery('#slider').data( 'nivo:vars' ).currentSlide + 1;

 var totalSlides = jQuery('#slider').data( 'nivo:vars' ).totalSlides;

 if ( currentSlide==-1 ) currentSlide = totalSlides-1;

 if ( currentSlide==totalSlides ) currentSlide = 0;

 jQuery( '.nivo-menu-container ul li' ).removeClass( 'selected' );

 jQuery( '.nivo-menu-container ul li:nth-child('+(currentSlide+1)+')' ).addClass( 'selected' );

}
</pre>
<p>I first got the current slide showing and the total number of slides:</p>
<pre class="brush: php; title: ; notranslate">

var currentSlide = jQuery('#slider').data( 'nivo:vars' ).currentSlide + 1;

var totalSlides = jQuery('#slider').data( 'nivo:vars' ).totalSlides;
</pre>
<p>I then needed to do some adjustments&#8230; For some reason the currentSlide variable that gets returned is 1 number less than what you&#8217;d think the variable would be. Not sure why (I didn&#8217;t dig through his code to figure out why), but the following seemed to work for me:</p>
<pre class="brush: php; title: ; notranslate">

if ( currentSlide==-1 ) currentSlide = totalSlides-1;

if ( currentSlide==totalSlides ) currentSlide = 0;
</pre>
<p>I then removed the &#8220;selected&#8221; class of the menu items, and added it back to the currently showing item:</p>
<pre class="brush: php; title: ; notranslate">

jQuery( '.nivo-menu-container ul li' ).removeClass( 'selected' );

jQuery( '.nivo-menu-container ul li:nth-child('+(currentSlide+1)+')' ).addClass( 'selected' );
</pre>
<p>The Full Code:</p>
<p>Here is the full (Nivo Initializing) script I used in my project</p>
<pre class="brush: php; title: ; notranslate">
jQuery( '.nivo-menu-container ul li a' ).click( function( e ) {
	e.preventDefault();
} );

jQuery( '#slider' ).nivoSlider( {
	captionOpacity: 1,
	controlNav: false,
	directionNavHide: false,
	manualAdvance: true,
	beforeChange: function(){
		var currentSlide = jQuery('#slider').data( 'nivo:vars' ).currentSlide + 1;
		var totalSlides = jQuery('#slider').data( 'nivo:vars' ).totalSlides;
		if ( currentSlide==-1 ) currentSlide = totalSlides-1;
		if ( currentSlide==totalSlides ) currentSlide = 0;
		jQuery( '.nivo-menu-container ul li' ).removeClass( 'selected' );
		jQuery( '.nivo-menu-container ul li:nth-child('+(currentSlide+1)+')' ).addClass( 'selected' );
	},
	afterChange: function(){
	},
	afterLoad: function(){

		jQuery( '.nivo-menu-container ul li:nth-child(1)' ).addClass( 'selected' );
		jQuery( '.nivo-menu-container ul' ).fadeIn();
		jQuery( '.nivo-menu-container ul li a' ).click( function( e ) {

			// Prevent default
			e.preventDefault();

			var $li = jQuery( this ).parent();
			var pos = $li.parent().children().index( $li );
			jQuery( '#slider' ).data( 'nivo:vars' ).currentSlide = (pos-1);
			jQuery( '.nivo-nextNav' ).trigger('click');
		} );

	}
} );
</pre>
<p>That&#8217;s it! Let me know if you have any comments or suggestions.</p>
<img src="http://feeds.feedburner.com/~r/metaphorcreations/~4/x93lCnJd8Dg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.metaphorcreations.com/nivo-slider-and-custom-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.metaphorcreations.com/nivo-slider-and-custom-links/</feedburner:origLink></item>
		<item>
		<title>Paginating WordPress</title>
		<link>http://feedproxy.google.com/~r/metaphorcreations/~3/eqGNRFIQtpU/</link>
		<comments>http://www.metaphorcreations.com/paginating-wordpress/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 01:06:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Customization]]></category>

		<guid isPermaLink="false">http://www.metaphorcreations.com/?p=55</guid>
		<description><![CDATA[After many Google searches and working out my own pagination code, I came across WordPress&#8217;s pre-built function paginate_links. If you think using &#8220;Previous Page/Next Page&#8221; is a little too generic, you&#8217;ll want to make use of this function. In this post, I&#8217;ll show you how to quickly create your own set of paginated links. Step 1 [...]]]></description>
			<content:encoded><![CDATA[<p>After many Google searches and working out my own pagination code, I came across WordPress&#8217;s pre-built function <a href="http://codex.wordpress.org/Function_Reference/paginate_links" target="_blank">paginate_links</a>. If you think using &#8220;Previous Page/Next Page&#8221; is a little too generic, you&#8217;ll want to make use of this function.</p>
<p>In this post, I&#8217;ll show you how to quickly create your own set of paginated links.</p>
<div class="m4c-alert" style="text-align:left;">
<p><strong>*Note:</strong> You can download a zip file containing the the following code (<a href="#55">at the bottom of this post</a>). I have built a child theme of the default <em>TwentyEleven</em> theme that replaces the &#8220;Previous/Next&#8221; page with paginated links.</p></div>
<hr />
<p><strong>Step 1<br />
</strong>Insert the following code into your functions.php file.</p>
<pre class="brush: php; title: ; notranslate">
function m4c_pagination() {

// Get total number of pages
global $wp_query;
$total = $wp_query-&gt;max_num_pages;

// If there is more than 1 page, display the links
if ( $total &gt; 1 ) {

// Get the current page
if ( !$current_page = get_query_var( 'paged' ) )
$current_page = 1;

// Get the user defined page structure
$structure = get_option( 'permalink_structure' );
$format = empty( $structure ) ? '&amp;page=%#%' : 'page/%#%/';

// Create the base structure
$base = get_pagenum_link(1) . '%_%';

// Modify base structure if search or archive page
if ( is_search() || is_archive() ) {
$big = 999999999; // need an unlikely integer
$base = str_replace( $big, '%#%', get_pagenum_link( $big ) );
}

$args = array(
'base' =&gt; $base,
'format' =&gt; $format,
'current' =&gt; $current_page,
'total' =&gt; $total,
'mid_size' =&gt; 4,
'type' =&gt; 'list',
'prev_text' =&gt; __( 'Previous', 'm4c_paginate_test' ),
'next_text' =&gt; __( 'Next', 'm4c_paginate_test' )
);

// Display the links
echo paginate_links( $args );
}
}
</pre>
<hr />
<p><strong>Step 2<br />
</strong>Add some styling to your style.css file.</p>
<pre class="brush: css; title: ; notranslate">
ul.page-numbers {
display: inline-block;
list-style: none;
background: url( assets/img/pattern.png );
margin: 20px 0;
padding: 10px;

-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
ul.page-numbers li,
ul.page-numbers li a,
ul.page-numbers li span {
font-size: 12px;
line-height: 12px;
color: #FFF;
}
ul.page-numbers li {
float: left;

}
ul.page-numbers li a {
text-decoration: none;
margin: 0 10px;
}
ul.page-numbers li a:hover {
color: #1982D1;
}
ul.page-numbers li a.next {

}
ul.page-numbers li span.current {
color: #1982D1;
font-weight: bold;
margin: 0 10px;
}
ul.page-numbers li span.next {

}
</pre>
<hr />
<p><strong>Step 3<br />
</strong>Add the pagination function to your index.php page (or another page that displays multiple posts).</p>
<pre class="brush: php; title: ; notranslate">
// Add custom pagination
m4c_pagination();
</pre>
<hr />
<p><strong>Resources<br />
</strong><a href="http://codex.wordpress.org/Function_Reference/paginate_links" target="_blank">http://codex.wordpress.org/Function_Reference/paginate_links</a></p>
<img src="http://feeds.feedburner.com/~r/metaphorcreations/~4/eqGNRFIQtpU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.metaphorcreations.com/paginating-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.metaphorcreations.com/paginating-wordpress/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.metaphorcreations.com @ 2012-02-14 14:38:34 -->

