Another Featured Content Slider Tutorial

All of my latest projects have involved putting a featured content slider of some kind on the home page. Everybody wants one. There are plenty of plugins both Jquery and WordPress (and Joomla and Drupal) that will build a slideshow for your images. You get a little less to choose from if the content being “slidered” is text and images.
And if using WordPress, you want to be able to use posts, featured images and the_ excerpt or the_content, right?

I’m using loopedSlider by Nathan Searles which has very recently been renamed Slides. I choose this plugin because it lets you choose from several different kinds of of transition effect for the sliding animation, has paging and can handle divs. In short it is highly flexible and extremely simple to use. Thank you, Nathan Searles for creating it and offering to the public.

If it’s so easy why do I need to write a tutorial? Because it got a little complicated when it came to using this plugin for WordPress posts. Here is a code example of a featured content gallery or slider that grabs 6 Posts according to a Tag. The amount of Posts is optional as is the Tag. The example code is not using the Loop and is safe to use in a theme file that is using the Loop – not in the Loop itself – that goes with out saying, I hope.

[php]<div id="featured-slider" class="bigbox">

<div id="slideshow">

<?php global $post;
$tmp_post = $post;
$myposts = get_posts(‘tag=featured&posts_per_page=6’);
foreach($myposts as $post) :
setup_postdata($post); ?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<span class="slideimage">
<?php the_post_thumbnail(‘big-slider’);?>
</span>

<span class="slidetext">

<h2><?php the_title();?></h2>

<span class="excerpt"> <?php the_excerpt();?></span>

</span>

</div><!–/post–>

<?php endforeach; wp_reset_query();?>

</div><!–/slideshow–>

<div class="bottom-slider-content">
<div id="slidernav"></div>
</div><!–/bottom-slider-content–>

</div><!–/.bigbox #featured-slider–>[/php]

Purists will not like the use of heading tags inside span tags but I found it somewhat easier to use span tags so that the slider knew when to stop sliding things.

Of course you have to download the slider JavaScript from the Slides Web site. Of course you have to be using Jquery in your theme. On the Slides Web site you will find many option examples and implementation codes. Here is how I configured mine. Note: I built this slideshow using loopedSlider so it might be helpful to visit that page as well for examples.

[js]$(document).ready(function(){
$(‘#slideshow’)
.after(‘<div id="slidernav">’)
.cycle({
fx: ‘scrollDown’,
// choose your transition type, ex: fade, scrollUp,scrollLeft,scrollRight, shuffle, etc…
speed: 1500,
// defines the number of milliseconds it will take to transition from one slide to the next.
timeout: 9000,
// specifies how many milliseconds will elapse between the start of each transition
pause: 1,
// so that pauses when user hovers over a slide
delay: 9000,
// set a delay before 1st slide starts transitioning
pager: ‘#slidernav’
//instructs the plugin to create navigation elements,
one for each slide, and add them to the container
identified by the value of the pager option.
});

});[/js]

Using the Featured Image in the Content Slider

If you look at the content slider code carefully you’ll notice I am using a Featured Image size named big-slider. I added this to my theme functions.php in order to be able to use a specific image size in the slider. Very useful for a consistent look.

Please backup functions.php before editing it!

[php]
add_theme_support( ‘post-thumbnails’ );
add_image_size( ‘big-slider’, 600, 315, true );
[/php]

If your functions.php already has the add_theme_support code don’t add it in again. Also, you can choose whatever size you want.
The first number is the image width, second is the height. You’re supposed to be able to have an open size , example: add_image_size( ‘big-slider’, 600, 999, true );

But I have had difficulty with this.

And then of course you can skip this and just put an array for the featured image directly into the slider query code,
example: the_post_thumbnail(array(600,315) );
instead of the_post_thumbnail(‘big-slider’);.

If you choose to do this you don’t need to add an image size to your functions.php but you should still take a look to see if your theme supports them. I know this is said over and over again but the image size you choose either in the query or the functions.php code does not work on already uploaded images.

In order to have the size you set kick in you must re upload the image and then choose it to be the featured image.

Download the example [download id=”13″]

For CSS (styling) and Javascript please visit Slides or loopedSlider.

Cufon.replace Even When Text Is Loaded by AJAX or jQuery

Recently I was confronted with a challenge: how to get the text of a heading that was being inserted with jquery+livequery to be replaced with Cufon.

The dilemma: Cufon couldn’t replace the text and it remained the plain, default typeface.

Luckily for me the last post this forum thread reported a way to fix it. Their solution was specific to the task they were trying to accomplish but it was simple to figure out how to re write to solve my problem.

If you are using Cufon already you’ll be familiar with this:

[php]Cufon.replace(‘h2.title’, { fontFamily: ‘greatfont’ });[/php]

If you’re familiar with jQuery you’ll be familiar with this, too:

[php]$("h2.title").livequery(function() {
$(this).text($("#breadcrumbs li:last-child").text());})[/php]

What I had to do was combine each into one function as a separate call from my other Cufon.replace code.
[php]$("h2.title").livequery(function() {
$(this).text($("#breadcrumbs li:last-child").text());
Cufon.replace(‘h2.title’, { fontFamily: ‘greatfont’ });
})[/php]

As added insurance I placed this right before the closing body tag:
[js]<script type="text/javascript">Cufon.now(); </script> [/js]

Use WordPress Rss Feeds to Show a Featured Content Gallery In Lightspeed Webstore Landing Page

WordPress+Simplepie+Lightspeed, awesome. In my last post I showed you how to make a featured content gallery with the_post_thumbnail. And in this post I talked about how to use Simplepie to show a WordPress feed on your Webstore.

I’m not going to lie, it requires extra work to use WordPress to enhance your Webstore. But it’s worth it. Because, lets face it, Webstores out of the box need a bit of pizazz.

In my last post I linked to a demo of a featured content gallery in a WordPress site. Snore, everybody has them on their WordPress sites, big deal, right? Well the only reason I built it was to learn how to build the exact same thing for a Webstore custom page using RSS feeds. And thanks to my friend David Auerbach over at dijitalfix.com I know how to code it into custom_page.tpl.php and have it show only on the landing page.

So enough chitter chatter, here’s the plain custom_page.tpl.php
[php]
<div style="padding: 15px 25px; line-height: 1.5em;"><?php echo $this->content; ?></div>
<?php if(isset($this->pnlSlider)): ?>
<br style="clear:both"/>
<?php $this->pnlSlider->Render(); ?>
<br style="clear:both"/>
<?php endif; ?>[/php]

Here’s my code:
[php]
<?php if($_GET[‘cpage’] && $_GET[‘cpage’]==’intro’):?>

<div id="product-specials">
<div id="slider">
<div id="sliderContent">
<?php foreach ($feed->get_items(0, 12) as $item): ?>
<div class="sliderImage"><?php print $item->get_description(); ?>
<span class="right"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?> </a></span></div>
<?php endforeach; ?>
<div class="clear sliderImage"></div>
</div><!–slidercontent–>
</div><!–slider–>
</div> <!–product specials–>
<?php endif; ?>
<?php echo $this->content; ?>

<?php if(isset($this->pnlSlider)): ?>

<?php $this->pnlSlider->Name = ”; ?>

<?php $this->pnlSlider->Render(); ?>

<?php endif; ?>
[/php]

This line makes sure the gallery only shows on the “Welcome to my Store” custom page:

[php]<?php if($_GET[‘cpage’] && $_GET[‘cpage’]==’intro’):?> [/php]

If you have re named the Page Key from intro to something else Please make sure to make the changes,OK?

I’ve coded it to show 12 feed items in the gallery. For more or less items, modify this line:

[php]<?php foreach ($feed->get_items(0, 12) as $item): ?> [/php]

A commenter said that they changed this line:
[php]<?php print $item->get_description(); ?>[/php]
To:
[php]<?php print $item->get_content(); ?>[/php]
and was happier with the results. Try both out.

This line
[php]<?php $this->pnlSlider->Name = ”; ?>[/php]
takes off the title of the Webstore product slider.
If you want it put back in just comment it out or cut it.

Ok, so before you run off and start modifying your custom page templates…
I hope it goes without saying you have to have WordPress installed on your server.
You also have to have Simplepie installed on your server.
Download Simplepie
Just make a folder called inc in your directory root and upload simplepie.inc to it.
Then make another folder called cache. That’s it, Simplepie is now installed.

Insert this code at the top of your index.tpl.php:
[php]
<?php
include_once $_SERVER[‘DOCUMENT_ROOT’] . ‘/store/inc/simplepie.inc’;
//full link to your wordpress, either just the site:
$feed = new SimplePie(‘http://www.mysite.com/wordpress/feed/’);
$feed2 = new SimplePie(‘http://www.mysite.com/wordpress/category/feed/’);
function image_from_description($data) {
preg_match_all(‘/<img src="([^"]*)"([^>]*)>/i’, $data, $matches);
}?>
[/php]
I’ve included 2 kinds of feed links there. One links to posts and one links to categories. If you have a Specific category add it in after /category and before /feed/.

There must not be blank space before the < ?php or you'll get that error message "Cannot modify header information,etc" and your store will go down. So make sure there is no blank space, ok? Also if you want to link to a specific category feed and you have a category base name make sure to include that name before the ending /feed/ like this: http://www.mysite.com/wordpress/my-category-base-name/feed/. I'm also assuming you have permalinks turned on. If you don't you should turn them on. If you want to show your whole blog in the featured content gallery slider doo dad--all the posts, no matter what category they are from, just use the link to the feed. Here are the kinds of rss feeds available. (Not sure about using the RSS .92 feed link)

Without Permalinks!

“RSS 2.0″ http://www.your_domain.com/?feed=rss2”
“RSS .92″ href=”http://www.your_domain.com/?feed=rss”
“Atom 0.3″ href=”http://www.your_domain.com/?feed=atom”

With Permalinks!

“RSS 2.0″ href=”http://domain.com/feed/”
“RSS .92″ href=”http://domain.com/feed/rss/”
“Atom 0.3″ href=”http://domain.com/feed/atom/”

Extra Stuff
Because the RSS feed grabs the link to the post if you don’t take a few extra steps your content gallery feed items will end up linking to back to the blog , not the products in the featured content gallery which, depending on how you want to use the gallery, might defeat your purposes.

Oh what to do? Use a plugin that redirects using Custom Fields!
I pasted this into function.php of my WordPress theme to redirect each post link to a specific product link using a custom field:
[php]
//set the options
$key = ‘redirect’;
$status = 301;

//Hook the link rewrite function into the page_link filter
//This part replaces the page URL, wherever it is outputted, with our custom URL
add_filter(‘page_link’,’custom_field_page_link’,10,2);
function custom_field_page_link($link,$id) {
//globalize vars
global $key;

$custom_page_url = get_post_meta($id, $key, true);
if(!empty($custom_page_url)) $link = $custom_page_url;
return $link;
}

//Hook the redirect function into the template_redirect action
//This part actually does the redirect, if necessary
add_action(‘template_redirect’,’custom_field_redirect’);
function custom_field_redirect() {
//globalize vars
global $wp_query, $key, $status;

$redirect = get_post_meta($wp_query->post->ID, $key, true);
if(!empty($redirect) && is_singular()) {
//And do the redirect.
wp_redirect($redirect, $status);
}
}
[/php]

Thanks to Nathan Rice for this!

How to use it
Each time you want to create a post that is going to be featured in the content gallery make sure to add “redirect”, without quotes, into the custom field Name. The Value area is where you paste the product URL. This will make sure that when the title of the post of the RSS feed item in the gallery is clicked on it will lead customers to the product details page, not the WordPress post.

For information on gallery slider and the javascript files you will need to get it running, go here http://www.serie3.info/s3slider/

3 New Ecommerce Designs

About a month ago we relaunched Chillyo.com with a new design – while I was working on it Nsha Club approached me about a new design for their site. I have to admit it I love designing Ecommerce websites. And I really love it when I am allowed to use my 2 favorite tools: WordPress and WordPress E-Commerce. Because I know how to use both tools pretty well by now, I am able to say to a client “I can do that, I can make that happen”.

I also designed a new site for an online Indian grocery using Lightspeed Webstore which went very well (and fast!) only 8 days from start day 1 to finish day which was today.
The client, India Stop Shop loved everything I did and if you’re in the same racket as me you’ll know that doesn’t happen all that often.