http://themethesis.com/wp-content/uploads/2010/05/featured-slider-thesis.jpg

Adding a Featured Content Slider to Thesis in 5 Quick Steps

May 26, 2010

in Tutorials

Add a Featured Slider to Thesis

One of the most popular features to have in websites today is the “featured content slider” (or “featured post slider”). It gives people a glimpse into your better posts and can catch their attention right away. For these reasons, it was one of the first features I included in my latest premium Thesis skin.

Today I’m going to tell you how you can do it for your own Thesis site (if for some crazy reason you don’t use Thesis Magazine :p)

So without further ado, here’s how to add a jQuery-powered featured content slider to Thesis in 5 quick steps:

The Instructions

I’m using the s3slider as my slider of choice. It doesn’t have navigation buttons, but I find it quick, easy, and great at doing what it does. You can try experimenting with different sliders if you feel comfortable and want other functionality.

  1. Download the necessary file from the s3slider homepage (s3Slider.js) and then upload it to your website.
  2. Turn on jQuery (Thesis Page Options > Javascript) and place
    <script src="js/s3Slider.js" type="text/javascript"></script>
    	<script type="text/javascript">
    	$(document).ready(function() {
       	$('#s3slider').s3Slider({
          	timeOut: 4000
       	});
    	});
    	</script>
    

    in the Additional Scripts section of the Thesis Site Options (where js/ is the directory of your s3lider.)

  3. Add this to custom_functions.php:

    add_action('thesis_hook_before_content', 'slider');
    function slider() {
    if (is_home()){
    ?>
    
    <div id="s3slider">
    
    <ul id="s3sliderContent">
    <?php $sub_loop_1 = new WP_Query('category_name=featured');
    while ($sub_loop_1->have_posts()) : $sub_loop_1->the_post();
    global $post;
    $post_image = get_post_meta($post->ID, 'thesis_post_image',$single=true);
    ?>
    
    <li class="s3sliderImage">
    <a href="<?php the_permalink(); ?>">
    <img src="<?php echo $post_image ?>" alt="<?php the_title(); ?>" />
              <span><strong>Featured - </strong><?php the_title(); ?></span></a>
          </li><?php endwhile; ?>
              <div class="clear s3sliderImage" />
       </ul>
    
    </div>
    
    <?php }
    
    }
    
  4. Add the following in custom.css:

    /* SLIDER */
    
    #s3slider {
       width: 580px; /* important to be same as image width */
       height: 300px; /* important to be same as image height */
       position: relative; /* important */
       overflow: hidden; /* important */
       margin-top: 35px;
       padding-bottom: 5px;
       margin-left: 1em;
    }
    
    #s3sliderContent {
       width: 580px; /* important to be same as image width or wider */
       position: absolute; /* important */
       top: 0; /* important */
       margin-left: 0; /* important */
       padding: 0px;
    }
    
    .s3sliderImage {
       float: left; /* important */
       position: relative; /* important */
       display: none; /* important */
    }
    
    .s3sliderImage span {
       position: absolute; /* important */
       left: 0;
       font: 21px/24px Helvetica, Arial, sans-serif;
       padding: 10px 13px;
       width: 100%;
       background-color: #000;
       filter: alpha(opacity=70); /* here you can set the opacity of box with text */
       -moz-opacity: 0.7; /* here you can set the opacity of box with text */
       -khtml-opacity: 0.7; /* here you can set the opacity of box with text */
       opacity: 0.7; /* here you can set the opacity of box with text */
       color: #fff;
       display: block; /* important */
       bottom: 0;	
    
       /*
           if you put
           top: 0; -> the box with text will be shown at the top of the image
           if you put
           bottom: 0; -> the box with text will be shown at the bottom of the image
       */
    }
    
    .clear {
       clear: both;
    }
  5. Create a category named “featured” and put the posts you’d like to have featured in that.

That’s it; you’re done. You now have a featured content slider on your homepage.

But what does it all mean!? A breakdown

Although following the above steps will have you up and running, learning some detail on what you’re doing will allow you to adapt this to other sliders and functions in the future.

add_action('thesis_hook_before_content', 'slider');
function slider() {
if (is_home()){
?>

This is the start of a function. It names it (slider) and places it before our content on our homepage.

<ul>
<?php $sub_loop_1 = new WP_Query('category_name=featured');
while ($sub_loop_1->have_posts()) : $sub_loop_1->the_post();
global $post;
$post_image = get_post_meta($post->ID, 'thesis_post_image',$single=true);
?>

This starts our loop, which will cycle through all the posts in the “featured” category (can be whichever category you’d like) and grabs the Thesis post image for display in a minute. Check out the Codex for more information on WordPress loops.

<a href="<?php the_permalink(); ?>">
<img src="<?php echo $post_image ?>" alt="<?php the_title(); ?>" />
          <span><strong>Featured - </strong><?php the_title(); ?></span></a>
      </li><?php endwhile; ?>
          <div class="clear s3sliderImage" />
   </ul>

This is our loop in action. It shows our post image and links it to the post. It also displays the title with “Featured – ” before it. You can learn more about WordPress template tags such as the_title here.

I hope you enjoyed the tutorial. If you have any questions, leave them in the comments and I’ll try my best to answer them. If you have any comments, leave them too, as I’d love to hear them. Thanks.

Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

You'll notice this site talks about the Thesis theme for Wordpress. Don't know what the heck that is? Find out.

{ 25 comments… read them below or add one }

Cara Jeanne May 26, 2010 at 7:55 pm

#1 in the instructions: where in my website do I put the s3slider file?

Reply

Matt Dunn May 26, 2010 at 7:57 pm

Wherever you’d like. Just make sure that your script src in the 2nd step points to it. For that reason, it’d probably be quickest to place it in a folder called js in the root of your domain.

Reply

Cara Jeanne May 26, 2010 at 8:03 pm

I know people like you (smart and all) hate people liking me asking questions. But at some point you had to learn too right? I really want to try this. The most I’ve done with downloads has been with plugins so I wasn’t sure where the js should go. Thanks for your patience in advance.

Reply

Lisa June 7, 2010 at 7:32 am

But… he told you where to put the js folder. The root of your domain. You don’t have to get snarky with him.
The root of your domain is the VERY FIRST area that’s in your public folder, the main part where all files and folders which are visible on the site are.
Make a new folder there, and call is js.

Reply

Neil May 26, 2010 at 8:49 pm

I think you may have forgotten to put the key in the ignition:

$(document).ready(function() {
$(‘#s3slider’).s3Slider({
timeOut: 4000
});
});

Reply

Matt Dunn May 26, 2010 at 8:54 pm

Wow. I sure did. Thanks.

Reply

Christina of Profresh Style October 3, 2010 at 2:24 pm

It’s not working for me. I just have one big white spot. Please help.

Reply

George Donnelly November 23, 2010 at 4:24 am

Ditto. I double-checked I did everything right.

Reply

NOMADWOMAN January 20, 2011 at 4:15 pm

HI

Where should this “extra code” go? My slider doesn’t look good :(

Reply

Neil May 26, 2010 at 9:00 pm

Sorry, I should also have said it works like a dream (when you add that) and thanks for posting it. Very useful.

Reply

ian harrison July 19, 2010 at 2:31 am

i have tried this about 15 times and cannot get it to work

i think the bit that i am having problems with is the custom_functions.php

sorry to be a pain, can you help?

Reply

Edward Beckett - Florida SEO December 5, 2010 at 9:53 pm

If your having WP whiteout issues … see if adding a closing php tag to your custom_functions.php file helps …

On the last line of the file simply add ‘?>’

that may help

HTH …

Reply

Ahmad Wali January 24, 2011 at 3:15 pm

is it possible to show all your recent posts as featured? I need slider to show recent posts as featured without adding them into “featured” category. Like dynamic content gallery it should pull last 6 recent posts. I don’t like dynamic content gallery plugin because my blog is running slow, but I need featured slider for thesis. I will be thankful if you guide me.

Reply

NOMADWOMAN January 31, 2011 at 5:23 pm

HI

I love this feature, but I want to have this on my front page and the blog itself on another page. When I set this through the WP reading settings the feature slider doesn’t work on either page.

Can you suggest how to do this on an alternative, static front page?

Reply

Thomas March 12, 2011 at 1:31 pm

Hello.
I have also the problem of the “white box”. I followed the step by step approach but it does not work.
Also, someone could explain to me where (and if) we have to add the extra code show in the comments.

Thank you very much!!

Reply

Rashid March 26, 2011 at 2:42 am

Hi guys,
I followed exactly on what the guide says, but i am getting this error.

Parse error: syntax error, unexpected ‘}’ in /home/fitgeekm/public_html/atrashids.com/wp-content/themes/thesis_18/custom/custom_functions.php on line 25
do help

Reply

discord March 27, 2011 at 7:36 pm

Hi,

I am doing lots of things right. But I do not know where to put

$(document).ready(function() {
$(‘#s3slider’).s3Slider({
timeOut: 4000
});
});

All I have is a big white space before the posts.

Reply

Arra June 3, 2011 at 9:56 pm

it’s doesn’t work for me :(

Reply

Sean June 5, 2011 at 2:51 am

I did what this post said but there is a white space and in the code I see that the content is there, but in firebug it’s just hidden. Any idea? Here is where I am experimenting with it: http://www.startuploans.org/dev/

Reply

Sean June 5, 2011 at 2:54 am

Nevermind. All you have to do is take out the display:none for .s3sliderImage

Reply

Koen June 11, 2011 at 2:22 pm

Hi guys,

I still have an issue with this. I did everything as described and moved the hook like “‘thesis_hook_before_header’”. I can see the spot for the slider but the post of the featured type isn’t showing. I can see that there is a small square with the name of the post over it but it just doesn’t show. Any idea’s?

Reply

Jean-Pol June 20, 2011 at 5:41 pm

Hi,

Thanks for the great tutorial but I would like to use this plugin to show specific pages instead of the last posts. I would also like for it to appear on a specific page instead of the posts page.

Any idea on how to do that?

Thanks in advance!

Reply

vietpha August 3, 2011 at 7:56 am

I’m having problem with css file. Css use:
filter: alpha(opacity=70); /* here you can set the opacity of box with text */
35.-moz-opacity: 0.7; /* here you can set the opacity of box with text */
36.-khtml-opacity: 0.7; /* here you can set the opacity of box with text */
37.opacity: 0.7; /* here you can set the opacity of box with text */
–> They don’t validate with css 2.1 and i check with css 3 that result is the same
Please help me.
Thanks you

Reply

bhavana menon August 30, 2011 at 2:26 pm

in thesis how to embed expandable text- easy way
like a heading with expand button to read more in the same page (like a slider opens)
any script for it? please help

Reply

bhavana menon August 30, 2011 at 3:15 pm

done everything and get this error
Fatal error: Cannot redeclare slider() (previously declared in /public_html/site/wp-content/themes/thesis_182/custom/custom_functions.php:4) in /public_html/site/wp-content/themes/thesis_182/custom/skins/thesismagazine/functions.php on line 254

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: