Thesis With More Than Two Teasers In Each Row

by Russell on September 18, 2010 · 80 comments

in how tos, thesis

Having produced an earlier solution for Thesis to have three teasers per row, I have had a few requests for solutions for 4 and even 5 teasers per row. These small teasers are useful where just a title and a thumbnail is to be displayed but no text.

The approach I have adopted to keep the code tidy is to put the JavaScript in separate files called jquery.n_teasers_per_row.js and put this file in the custom folder where the n is either three, four, five or six. This approach keeps the PHP in the Thesis custom_functions.php simple.

Three Teasers Per Row

I put the JavaScript in a file ../themes/thesis/custom/jquery.three_teasers_per_row.js

function three_teasers_per_row() {
  last_teaser = jQuery('.teaser').size()-1;
  jQuery('.teaser').each(function(index) {
     if ((index % 6) == 2) {
         jQuery(this).clone().appendTo(jQuery(this).parent().prev());
         jQuery(this).remove();
     }
     if (((index % 6) == 3) && (index < last_teaser)) {
         jQuery(this).clone().prependTo(jQuery(this).parent().next());
         jQuery(this).remove();
     }
  });
  jQuery('.teasers_box').each(function(index) {
     if (((index % 3) == 1) && (jQuery(this).children().size() == 0))  {
         jQuery(this).remove();
     }
  });
  jQuery('.teaser').each(function(index){
    jQuery(this).addClass('teaser3').removeClass("teaser_right");
  });
}
jQuery(document).ready( function () { three_teasers_per_row(); });

Here is the CSS. You may need to tweak the width according to the size of your content area

.custom .teaser3 { width: 210px; padding-right:20px; } //change width to allow 3 columns
.custom .teaser3 .format_teaser p { display: none } //hide the text but not the teaser thumbnail

Here is the PHP to gi custom_functions.php. In this example I am enabling, three teasers per row on just the home page

function add_jquery_stuff () {
   if (is_home()) {
      echo ('<script type="text/javascript" src="'.THESIS_CUSTOM_FOLDER.'/jquery.three_teasers_per_row.js"></script>');
   }
}
add_action('wp_footer', 'add_jquery_stuff');

Four Teasers Per Row

I put the JavaScript in a file ../themes/thesis/custom/jquery.four_teasers_per_row.js

function four_teasers_per_row() {
  jQuery('.teaser').each(function(index) {
     if ((index % 4) > 1) {
         jQuery(this).clone().appendTo(jQuery(this).parent().prev());
     }
  });
  jQuery('.teasers_box').each(function(index) {
     if ((index % 2) == 1) {
         jQuery(this).empty().remove();
     }
  });
  jQuery('.teaser').each(function(index){
    jQuery(this).addClass('teaser4').removeClass("teaser_right");
  });
}
jQuery(document).ready( function () { four_teasers_per_row(); });

Here is the CSS that is similar to that above. You may need to tweak the width according to the size of your content area

.custom .teaser4 { width: 150px; padding-right:20px; }
.custom .teaser4 .format_teaser p { display: none }

Five Teasers Per Row

I put the JavaScript in a file ../themes/thesis/custom/jquery.five_teasers_per_row.js

function five_teasers_per_row() {
  last_teaser = jQuery('.teaser').size()-1;
  jQuery('.teaser').each(function(index) {
     i = (index % 10);
     if ((i== 2) || (i ==3) || (i==8) || (i==9))  {
         jQuery(this).clone().appendTo(jQuery(this).parent().prev());
         jQuery(this).remove();
     }
     if (i==4)  {
         jQuery(this).clone().appendTo(jQuery(this).parent().prev().prev());
         jQuery(this).remove();
     }
     if ((i==5) && (index < last_teaser)) {
         jQuery(this).clone().prependTo(jQuery(this).parent().next());
         jQuery(this).remove();
     }
  });
  jQuery('.teasers_box').each(function(index) {
     i = (index % 5);
     if (((i == 1) || (i==2) || (i==4)) && (jQuery(this).children().size() == 0))  {
         jQuery(this).remove();
     }
  });
  jQuery('.teaser').each(function(index){
    jQuery(this).addClass('teaser5').removeClass("teaser_right");
  });
}
jQuery(document).ready( function () { five_teasers_per_row(); });

Here is the CSS that is similar to that above. You may need to tweak the width according to the size of your content area

.custom .teaser5 { width: 120px; padding-right:15px; }
.custom .teaser5 .format_teaser p { display: none }

Six Teasers Per Row

I put the JavaScript in a file ../themes/thesis/custom/jquery.six_teasers_per_row.js

function six_teasers_per_row() {
  jQuery('.teaser').each(function(index) {
     if ((index % 6) > 1) {
         jQuery(this).clone().appendTo(jQuery(this).parent().prev());
     }
  });
  jQuery('.teasers_box').each(function(index) {
     if ((index % 3) > 0) {
         jQuery(this).empty().remove();
     }
  });
  jQuery('.teaser').each(function(index){
    jQuery(this).addClass('teaser6').removeClass("teaser_right");
  });
}
jQuery(document).ready( function () { six_teasers_per_row(); });

Here is the CSS that is similar to that above. You may need to tweak the width according to the size of your content area

.custom .teaser6 { width: 100px; padding-right:10px; }
.custom .teaser6 .format_teaser p { display: none }

Please feel free to make a donation is you find any of the above useful or you would like me to do for the tutorial for seven or more teasers per row.

Thanks

Russell

{ 80 comments… read them below or add one }

serge lerner September 29, 2010 at 4:10 am

first of all thanks alot !
the thing is i cant manage to work this… i think i do everything right. i can see that i’ve add the JavaScript file to the wp_head and it look right. the css i add though looks overwritten by something.

im using thesis 1.8, any chance this is not working on thesis 1.8 ?

do i suppose to do anything else on the back end ?

unfortunately i don’t have an online site to show you. im running this on wamp.

Russell September 29, 2010 at 11:56 am

Try using Internet Explorer and check the status bar at the the bottom left on the page for errors. Double click to see an error message. It might be that jQuery is not loaded at all or it might be that two versions of jQuery are running. These are the most likely issues.

If that does not work you can send me the html source of the page

Regards

Russell

serge lerner September 29, 2010 at 1:25 pm

I’ve checked with Internet Explorer and it does have an error message:
Webpage error details:

Message: Object expected
Line: 24
Char: 1
Code: 0
URI: http://localhost/wordpress/wp-content/themes/thesis_17/custom/jquery.three_teasers_per_row.js

what can i do ?
thanks again!

Russell September 29, 2010 at 2:04 pm

Line 24 is jQuery(document).ready( function () { three_teasers_per_row(); }); so it is probably a jQuery issue.

You need to view the page source

Is jQuery being loaded before this script?

The jquery load might be something like

<script type=’text/javascript’ src=’http://www.wordpresswise.com/wp-includes/js/jquery/jquery.js?ver=1.4.2′></script>

serge lerner September 29, 2010 at 2:17 pm

no its not being loaded…
how do i load it ?

Russell September 29, 2010 at 2:27 pm

You can safely move the three_teasers_per_row.js file into the footer (before the </body> tag where there is less chance of the problem being the load order of the scripts

serge lerner September 29, 2010 at 2:35 pm

ok i’ve managed by putting some jQuery loading code into the thesis Additional Scripts panel.
Thanks for everything! this is very helpful.

Russell September 29, 2010 at 3:03 pm

Glad you got it working!

Matt October 18, 2010 at 7:20 pm

I’m having the same problem in thesis 1.8 I went over the tutorial a few times and can’t seem to find the problem of it not working correctly. What code exactly did you insert in the additional scripts panel?

serge October 18, 2010 at 9:24 pm

Try going to the Site Options – > Additional Scripts and paste the next code:

This line loads jQuery from google

Russell October 19, 2010 at 4:31 pm

Hi Serge

Thanks for your comment. Pasting code in comments can be problematic and sometimes they get stripped out automatically by Wordpress.

I have installed the Syntax Highlighter Evolved plugin, which allows code to be displayed within posts, and have just checked that it works in comments..

Please put your javascript code between [ code][/code] tags with square brackets but please omit the extra space which I need to included here to made the tags visible (otherwise they would hav ebeen translated by the plugin

For example, this what the code looks like when surrounded by the code and /code tags

[code]<script text="javascript">javascript code here></script>[/code]

serge October 19, 2010 at 5:51 pm

Hi Russell, thanks for the update,

here’s the code that loads jQuery from google:

[code]<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot; type="text/javascript"></script>[/code]

Gregory October 26, 2010 at 9:12 pm

Hello!,
This dpesnt work with Thesis 1.8 .
Anyone able to get iot working on 1.8 ?
let me know pls.

Gregory

Gregory October 26, 2010 at 9:24 pm

Hi! Russel,
I just re checked and in IE I am getting an error. same as you mentioned above about jquery.
But when i look up the source I can see it at the bottom

This is before the tag

Does this need to be showing up in the header position or something else ?
If so how do I move the location where the javascript call shows.

Gregory

Russell October 26, 2010 at 9:52 pm

Hi Gregory,

This site is Thesis 1.8 and the 3 teasers per row is working fine on the home page. It renders fine on Firefox, Chrome, Internet Explorer and Safari on PCs and Firefox, Chrome and Safari or Macs

The issue is likely to a plugin conflict, theme issue or a javascript issue that is specific to your site.

Regards

Russell

Russell October 26, 2010 at 9:55 pm

Hi Gregory,

When clicking on the error you should get a more detailed message with a line number. Do a “view source” to discover the line.

Is jQuery being loaded at all? Are you using the Wordpress or the Google version of jQuery. Are you using Thesis’s option to include jQuery?

If you give me your URL I can take a look if you would like.

Regards

Russell

Gregory October 27, 2010 at 3:04 am

Hi! Russel,
The link to the site is http://incomeink.com/
In IE its still showing the error icon, but I am able to see the following line in the view source before the tag:

Can you pls take a look at it and suggest how I can have this working.
Thanks for your help and time.

Gregory
Gregory´s last [type] ..Test Post Six

Gregory October 27, 2010 at 3:07 am

Sorry just noticed I had not replied to this part of your questions:
I have only enabled the Jquery from within the Thesis Javascripts in Design Options.

Gregory
Gregory´s last [type] ..Test Post Six

Gregory October 27, 2010 at 1:51 pm

Hi! Russel,
I do not have any plugins installed except the Thesis Open Hooks. The Theme is the Free Network News from WPBlogger.com.
Look forward to your reply

Regards
Gregory

Gregory October 27, 2010 at 2:15 pm

Hi! Russel,
Ok tried the whole thing again and this time it worked.
Thanks for the help and great code.

Regards
Gregory

Russell October 27, 2010 at 3:27 pm

Glad it is all working for you

Cheers

Russell

Gregory October 27, 2010 at 9:26 pm

Hi! Russell,
Double Cheers for you – its your code that did it.

How can one remove the text from showing up and have only the images displayed.
As per your code I have the following in the custom css file but the text is still showing .
[code].custom .teaser3 .format_teaser p { display: none }[/code]

Could you tell me how to have this working without the text and showing only the images.

Regards
Gregory

Russell October 27, 2010 at 10:09 pm

Hi Gregory

I can’t see why it is not working – my suggestion is to try changing the CSS

[code].custom .teaser.teaser3 .format_teaser { display: none; } [/code]

or if that does not work, try

[code].custom .teaser3 .format_teaser { display: none !important; } [/code]

Gregory October 27, 2010 at 11:08 pm

Hi! Russell,
I tried both the options you gave… Unfortunately none of them worked.
Is’nt that really odd. I am all at sea here. :-(

Regards
Gregory

Russell October 27, 2010 at 11:29 pm

What you are doing should work.. I do not see why the CSS for .teaser3 .format_teaser is not being applied.

Your site is behaving as if the line that includes the CSS for .teaser3 display: none does not exist.

I can only suggest doing something like moving the line for teaser3 to the top of the custom.css file and retyping it carefully.

Sounds a bit crazy but I have encountered issues with non-printable invisible control characters in files that means instructions are ignored.
Why crazy? Because when I suggest you delete the invisible characters then you say “which characters?” and I say “the invisible ones” – right next to the visible ones. Sadly, this has fixed the problem more times than I would care to remember. That’s computers for you.

However, despite the rant, the problem here is completely soluble; it just takes a systematic approach to identify what is not working and why.

It is just a matter of getting the right CSS that works for your theme and your set of plugins

Gregory October 28, 2010 at 12:05 am

Hi! Russell,
Thanks for the feedback. Am going to read it again and then try it over as suggested. Hopefully it should do the trick. Will let you know how it goes.
Thanks for your tireless support on this.

Regards
Gregory!
Gregory´s last [type] ..Test Post Six

Wo November 13, 2010 at 2:09 pm

Love this. Worked first time. It looks great. Thanks so much. One thing. I would like to see the text under the Teaser images. I took out the second line of code in the CSS but the text hasn’t come back. Any idea?
Wo´s last [type] ..Christmas Menu

Wo November 13, 2010 at 2:11 pm

My bad. Needed to change it in Design Options. Thanks again.
Wo´s last [type] ..Christmas Menu

Clarence Johnson November 17, 2010 at 12:58 am

Hi Russell,

Thank you for sharing this JavaScript solution.

I am having a challenge getting the “Three Teasers Per Row” to work and I was wondering if there if a step that is missing that it is presumed that the visitors like myself would know. Bear with me….

Do I need to select a JavaScript library in the Design Options—>Home Page Display Options and/or Design Options—>JavaScript?

Do I need to amend .THESIS_CUSTOM_FOLDER. portion in the PHP code that is inserted into the custom_functions or just use the whole code as is?

Thanking you in advance.
Clarence Johnson´s last [type] ..Chilly Eyewear

Russell November 17, 2010 at 6:43 pm

Hi Clarence,

I have made a tweak to the php in custom_functions.php if you would like to check out http://www.wordpresswise.com/more-than-two-teasers-per-row-in-thesis-461. It now puts the php in the footer rather than the header. All you need to do is change the add_action line to refer to wp_footer instead of wp_head and then make sure jQuery is enabled

In the Thesis Design Options – Javascript – you need to enable jQuery if it is not already enabled by some other plugin you are using. Note that there may be issues if you have both Wordpress and Thesis/Google version of jQuery running, but this is an unlikely scenario for you as a I think you have no jQuery running rather than 2 versions

Please let me know how you get on. Send me your URL if you are still having problems

Regards

Russell

Clarence Johnson November 17, 2010 at 7:10 pm

Russell,

One quick questions…as per my initial e-mail. Please provide me with an answer for the question below – thanks.

Do I need to amend .THESIS_CUSTOM_FOLDER. portion in the PHP code that is inserted into the custom_functions or just use the whole code as is?
Clarence Johnson´s last [type] ..Chilly Eyewear

Russell November 17, 2010 at 7:19 pm

Clarence,

Sorry if I was unclear.

The answer is Yes.

In the THESIS_CUSTOM_FOLDER bit change

add_action(‘wp_head’, ‘add_jquery_stuff’);

to

add_action(‘wp_footer’, ‘add_jquery_stuff’);

and also enable jQuery on the Thesis Design Options Javascript page

Clarence Johnson November 18, 2010 at 1:19 pm

*GOOD NEWS*

Russell,

Thank you (again) for this JavaScript solution…I now have it working. I decided to use the four column teaser layout instead of the three. Below are the settings I used to get it working and you will notice that I do not need to add anything to the custom_functions.

The four column layout can be seen on my website’s homepage, category, tag, and month pages.

*Settings*

#1 – Design Options —-> Home Page Display Options —–>JavaScript:
- I selected the jQuery library

#2 – Design Options —-> JavaScript—–>Sitewide JS Libraries:
- I selected the jQuery library

#3 – Design Options —-> JavaScript—–>Embedded Scripts:
- I populated the field with the JavaScript tag that you created (e.g. )

note: the specific of the aforementioned script would be unique for each webmaster.

#4 – Custom.css
- I added .custom .teaser4 {width: 180px;} to my custom css file.

#5 – WordPress reading settings (via the Dashboard)
- for my website, I change the “Blog posts show at most” from 10 to 16
Clarence Johnson´s last [type] ..Chilly Eyewear

Wo December 12, 2010 at 5:55 pm

The 3 teasers in a row works fantasticly well on the home page. But when you go into categories it’s only two across with the third underneath and a big gap between the two. Have you got any ideas why that might be the case? The website is

http://covehotel.woisme.myzen.co.uk

Thanks,

Wo
Wo´s last [type] ..“Reviews of the Decade” – Guardian

Russell December 12, 2010 at 6:01 pm

Wo,

My example had a line of code that only applied the 3 teasers per row on the home page. (e.g if (is_home()).. etc)

Did you remove this line from your code?

Regards

Russell

mamikaze February 3, 2011 at 10:50 pm

Thanks! I love this script :) What do I change to show the excerpt? ?

Russell February 24, 2011 at 12:53 am

Have you tried changing the Thesis Display Options | Archives from “everything a teaser” to ” post excerpts”?

joemar March 10, 2011 at 4:50 am

hello russel, can i request what it looks like when you implemented the stated code above? mine here are not working. :( . Or anyone on the group

joemar March 10, 2011 at 6:20 am

thanks russel now my work is now working… more tutorials please :)
joemar´s last [type] ..Surprised Kitten

Russell March 10, 2011 at 10:12 am

What was wrong with your first attempt, by the way? It may be worth sharing this if it could help other people

Regards

Russell

Russell March 10, 2011 at 10:13 am

You can see “three teasers per row” in action on the home page of this site, and the “one teaser per row” on the archive pages

joemar March 20, 2011 at 7:20 am

Sorry for the late response, i just added my default custom folder url and it works :) , Thanks again and more tutorials on thesis please :)
joemar´s last [type] ..Rebecca Black “FRIDAY”

Louis March 20, 2011 at 9:10 pm

Hi Russell,

I’m having real issues with this. I’m getting this error:

[code] function add_jquery_stuff () { if (is_home()) { echo (''); } } add_action('wp_head', 'add_jquery_stuff'); [/code]

Please can you help me with this? My site is http://mossycleft.com

Louis March 20, 2011 at 10:31 pm

Hi Russell,

I’m having trouble with the implementation of the code in the custom_funtions.php

I keep getting this error: Parse error: syntax error, unexpected ‘{‘ in /home/mossy/public_html/wp-content/themes/thesis_18/custom/custom_functions.php on line 3

Please can you let me know how to add this code correctly:

[code] function add_jquery_stuff () {
if (is_home()) {
echo ('<script type="text/javascript" src="'.THESIS_CUSTOM_FOLDER.'/jquery.three_teasers_per_row.js"></script>');
}
}
add_action('wp_footer', 'add_jquery_stuff'); [/code]

Thanks for your help

Louis

joemar March 21, 2011 at 6:48 am

Russel,
Hello i got it working until i notice that i had an error on my footer part of my site. hope you could help me currently i don’t have any plugins and followed the instruction above. I try to get my error by making an image. Here is the Link:
[IMG]http://i56.tinypic.com/n6ov38.jpg[/IMG]

Russell March 21, 2011 at 12:09 pm

What is the URL of the site? What are the first 5 lines of the file?

joemar March 21, 2011 at 1:10 pm

this is the url of my site, http://iidnet.org/demo/fbc/

then i go to thesis theme option java script sitewide js libraries and enable jquery and put the code to the embed script:
function add_jquery_stuff () {
if (is_home()) {
echo (”);
}
}
add_action(‘wp_footer’, ‘add_jquery_stuff’);

after saving it and see my site the code below it.

Thanks in advance,

joemar
joemar´s last [type] ..AVG Anti Virus 2011

Louis March 21, 2011 at 7:12 pm

Hi Russell,

As requested this is the first 5 lines of the file:
[code]
function add_jquery_stuff () {
   if (is_home()) {
      echo ('<script type="text/javascript" src="/wp-content/themes/thesis_18/custom/jquery.three_teasers_per_row.js"></script>');
   }
}
add_action('wp_footer', 'add_jquery_stuff');
<?php

// Using hooks is absolutely the smartest, most bulletproof way to implement things like plugins,

[/code]

Thanks,

Louis
Louis´s last [type] ..Crysis 2 – Trailer

Russell March 21, 2011 at 8:16 pm

Looks like you are missing

Louis March 21, 2011 at 8:46 pm

Thanks Russell,

I’ve now changed the custom_functions.php to:

[code]
<?php
function add_jquery_stuff () {
   if (is_home()) {
      echo ('<script type="text/javascript" src="/wp-content/themes/thesis_18/custom/jquery.three_teasers_per_row.js"></script>');
   }
}
add_action('wp_footer', 'add_jquery_stuff');
?>
[/code]

Now the homepage says:
[code]
Parse error: syntax error, unexpected '{' in /home/mossy/public_html/wp-content/themes/thesis_18/custom/custom_functions.php on line 3
[/code]

The error is currently live on the server.

Sorry if i’m missing something really obvious.

Thanks

Louis
Louis´s last [type] ..Crysis 2 – Trailer

Leave a Comment

CommentLuv badge

Spam Protection by WP-SpamFree

Previous post:

Next post: