How To Hack Thesis To Have More Than Two Teasers Per Row

by Russell on November 19, 2009 · 28 comments

in thesis

I have a client who has specific requirements regarding their home and archive pages: the home page needed to show 3 teasers with titles and thumbnails but no text; and the archive page needed to show a single teaser per row that included title, thumbnail and text excerpt.

Out of the box, Thesis shows two teasers per page: this is hard coded in the thesis/lib/functions/loop.php file. Not good. It gives two teasers a page but I need 3 on the home pages and 1 on an archive page. I feel a hack coming on…

Anyway, having looked for some time at doing something clever in custom_functions.php I eventually gave up and decided to make minor tweaks to Thesis core.

Changes to loop.php

As well as adding some new elements to custom.css I modified thesis_home_loop as follows to remove the hard coding of two teasers per row but still defaulting to two teasers per row – in other words the normal behaviour is unchanged:

function thesis_home_loop() {
    $post_count = 0;
    $teaser_count = 0;
    global $teasers_per_row;
    if (empty($teasers_per_row)) $teasers_per_row = 2;

    while (have_posts()) {
      $post_count++;
      the_post();

      if (thesis_is_teaser($post_count)) {
        $teaser_count++;
        $top = ($post_count == 1) ? ' top' : '';
        $open_box = "";
        if (($teasers_per_row== 1)
        || (($teaser_count % $teasers_per_row)== 1))
            $open_box = '<div class="teasers_box' . $top . '">' . "\n";
        $close_box = ($teaser_count % $teasers_per_row) == 0?'</div>':'';
        $right = (($teaser_count % $teasers_per_row) == 0) && ($teasers_per_row > 1) ;

        if ($open_box != '') {
            echo $open_box;
            thesis_hook_before_teasers_box($post_count);
        }

        $classes = $teasers_per_row==2?"teaser":("teaser teaser".$teasers_per_row);
        thesis_teaser($classes, $post_count, $right);

        if ($close_box != '') {
            echo $close_box;
            thesis_hook_after_teasers_box($post_count);
        }
      }
      else {
        $classes = 'post_box';

        if ($post_count == 1)
            $classes .= ' top';

        thesis_post_box($classes, $post_count);
        $close_box = "noteaser";
      }
    }
    if (($teaser_count > 0) && ($close_box == ''))
      echo '</div>' . "\n";
}

Changes to teasers.php

I also changed one line in wp-content/themes/thesis/lib/functions/teasers.php so it handles the input parameter $classes.

$classes = 'teaser';

is replaced by

if (stripos($classes, 'teaser') === false) $classes = 'teaser';

This means the input parameter $classes is not ignored and can be set externally, to either teaser1 or teaser3 depending on how many teasers per row I want to display.

Changes to custom_functions.php

The final PHP change is in custom_functions.php as follows:

add_action('thesis_hook_before_content_box','set_teasers_per_row');
$teasers_per_row = 2;
function set_teasers_per_row(){
  global $teasers_per_row;
  $teasers_per_row = is_home()?3:(is_category()?1:2);
}

This means that on the Home page we have 3 teasers per row; on a categories page we have 1 teaser per row and on any other page we have the default on two teasers per row.

Changes to custom.css

The additional lines in custom.css were as follows to set the column appropriately according to the number of teasers per row:

.custom .teaser1 { width: 55em; }
.custom .teaser3 { width: 20em; }
.custom .teaser3 .myteaser {display : none}

The first line handles one teaser per row; the second line allows 3 teasers per row; and the third line hides any content qualified by the myteaser class where 3 teasers are being displayed, i.e. the home page: this last point was a requirement of my client where she wanted only a title and an image to appear for teasers on the home page.

Creating a Teaser For Display As One Per Row Or Three Per Row

A typical teaser/excerpt is as follows consisting of a left aligned thumbnail and some text.

<img style="float:left;padding-right:10px" src="http://client-xxx.com.s3.amazonaws.com/thumb1.jpg"/><div class="myteaser"><h2>Latin Tips</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc quam lacus, imperdiet in mollis eget, pellentesque sit amet mauris. Pellentesque euismod sodales metus ut consequat. Sed a neque eget orci pharetra dignissim. In hac habitasse platea dictumst.</p></div>

On an archive page the teaser appears as a thumbnail with some text with a single teaser per row but on the home page only the thumbnail appears and we have three thumbnail per row.

Suggested Improvements For Thesis

Ideally I would like Chris Pearson to amend the teaser handling so it is more flexible.
I would suggest he removes the hard coding of 2 teasers a row and updates the teaser settings on the Thesis Design Options page so the user can choose between 1, 2, 3 or 4 teasers per row. Hey, I have done the coding, all he needs is a little ‘cut and paste’.

Google Buzz
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

{ 28 comments… read them below or add one }

ohbrooke December 15, 2009 at 3:10 am

I’m hoping to add a graphic that says “More Stories” above the entire teaser section. How can I add a div in this teaser.php page to add that? Thanks for your tuts!

Sushant December 20, 2009 at 1:45 pm

Thanx Russell, I just converted my blog to 3 teasers per row .
Also made a little change to custom css for right (3rd teaser) which is default to float:right and was not adjusting with the other 2 teasers.

.custom .teaser_right{ float:left; }
Sushant´s last blog ..Well Done Abba movie cast, synopsis, poster, first look My ComLuv Profile

Lily January 2, 2010 at 8:56 pm

Thanks for this, but what ll happen when new version comes out..
It ll override all the changes :-(

One of the purposes of Thesis theme is to avoid messing with core files, but as we can see here, they didn’t think about people who need to have more than 2 teasers per row.. Sadly..

Russell January 3, 2010 at 9:18 am

Lily, Lily, Lily

You are right – it is a temporary hack. It would need to be re-introduced and tested every time there is an uipgrade.

I will post on the diythemes.com forum and ask godhammer to do his bit and try and influence Chris Pearson to include it in his next release.

You probably already know this but if you want just a single teaser per page you can do this without changing/hacking any thesis code, see http://diythemes.com/forums/customization/9320-change-teaser-display-one-column.html

Penny April 12, 2010 at 12:16 pm

Great sharing, thank you! I’ve been looking for this hack for the longest time!! So glad to have found it here, I’m gonna try it out! :)
Penny´s last blog ..Lovely butterfly sleeves mini dress in chiffon My ComLuv Profile

Prince Vasquez April 16, 2010 at 11:31 pm

I can’t seem to make 3 teasers in a row to work :(
Prince Vasquez´s last blog ..Dream-Fantasy Photo Effect on Photoshop Using Gaussian Blur My ComLuv Profile

Russell April 21, 2010 at 12:26 am

Please elaborate on the problem and supply a URL to the page. The URL you referred to does not appear to be the Thesis Theme

Clay April 28, 2010 at 1:51 pm

Hey Russell,

Currently, my Thesis 16 template has 8 Teaser Boxes. I need 10.

Do you know of a decent way to do this?

-Clay

Russell April 28, 2010 at 4:37 pm

Clay,
This might be just a matter on going to Wordpress Settings under Reading and setting the number of blog posts to ten more than the number of full posts you display on the page. In my case I display one full post on the home page, search results page and archive pages. So, to display 10 teasers as well the the one full post I would change the default setting from 10 to 11.
How To Show Ten Teasers on the Home Page

Nina May 12, 2010 at 11:04 pm

Hi Russell,

Is this hack much different for Thesis version 1.7?

Shannon May 13, 2010 at 5:32 am

Tried to implement this solution but got an error that it couldn’t find the thesis_post_box function. Do you know if that’s changed names? I tried to research it but came up with nothing on my own.

Thanks for all your work putting this together. Hopefully Thesis will make this easier in a future version.
Shannon´s last blog ..I didn’t change my clothes for 3 days My ComLuv Profile

Russell May 13, 2010 at 11:31 am

Hi Shannon,

The function thesis_post_box still exists in version 1.7. Look in wp-content/themes/thesis_17/lib/functions/loop.php.

I have not yet upgraded to Thesis 1.7 on the particular site where I did the hack but will look at this today and let you know if I find anything useful.

Regards

Russell

Shannon May 13, 2010 at 4:43 pm

Thanks for your reponse, Russell. You’re right. It does. Not sure why I got the error that it couldn’t find it when I tried your code. Will try again.

Shannon May 13, 2010 at 4:46 pm

Oh, here’s what happened: I copied and pasted your loop.php code over all of my existing loop.php code instead of just for that 1 function.

Note to self: read instructions more closely.
Shannon´s last blog ..I didn’t change my clothes for 3 days My ComLuv Profile

Shannon May 13, 2010 at 4:57 pm

And for my 3rd comment in a row, I got it to work. Thanks again for your work on this. Hopefully Mr. Pearson will copy and paste it into the next version of Thesis. :)
Shannon´s last blog ..I didn’t change my clothes for 3 days My ComLuv Profile

Russell May 13, 2010 at 9:11 pm

Hi Shannon,

Thanks for the blow by blow account. Glad you got it working

I did chat/tweet with Chris about 2 months ago and he agrees that teasers should be made more flexible.

However it is not the top of his priority list but I think he will get to it at some point.

Best Regards

Russell

Nina June 4, 2010 at 2:39 am

Thanks for the hack! I found this useful for a client project I am working on with Thesis 1.7.

A couple of things:

Just to reiterate what you told Lily – it is not advised to edit core files unless you know what the heck you’re doing. Why? Simply because you won’t be able to update to newer versions of Thesis without doing this all over again. So if you’re hacking the teasers for a client, be sure to advise them that they will need your help in hacking it again if they want to update to the latest version of Thesis.

Under the heading “Changes to teasers.php”, you need to omit the

Thanks again!

Nina June 4, 2010 at 2:41 am

Ah, it didn’t display the code – omit the em
Nina´s last undefined ..Response cached until Sat 5 @ 2:39 GMT (Refreshes in 23.98 Hours) My ComLuv Profile

Russell June 4, 2010 at 10:01 am

Hi Nina,

Thanks for your feedback. And of course I agree with you completely about the dangers of editing core files.

I have removed the wayward </em> from the code example. Thanks for this correction.

If approaching this problem again I would take a different approach by using jQuery to rewrite the teasers – this has the advantage of leaving the core Thesis code untouched.

The next time Thesis is upgraded to a new version I will publish the jQuery solution rather than try and reimplement the Thesis hack (assuming Chris does not fix it first)

Rob McGuire June 19, 2010 at 5:29 am

Thanks for the guide on creating a 3 column layout for the teasers in Thesis. This proved to be pretty valuable to me, as this week I had to build a site that called for this feature.

I did one part of your guide a little differently though. I copied the thesis_home_loop into my custom functions file and just renamed the function for use in a different function. The output came out the same, but I figured by adding the loop to the custom file there would be one less thing to modify on any future upgrades.

Russell June 20, 2010 at 10:17 am

Hi Rob,

Thanks for your comment. Putting a version of the thesis_home_loop in custom_functions.php is much more maintainable. But how did you get it to run your version rather than the original? Did you code the entire page or did you find a suitable hook?

Rob McGuire June 20, 2010 at 4:11 pm

Russell,

I thought about what I said after I wrote that and realized the exact way I said it would be a little confusing.

The project I was working on had it to where there was a page created that only showed posts from category “A” while the main blog page would then show all posts except category “A” posts. So what I did was copy the thesis_home_loop function that you had listed above in this article into my custom functions file and renamed the loop function. I then called this renamed function in the other function that created the custom page template I needed.

Since I was doing it this way to create a custom page template it wasn’t a problem, but I think editing core files is still necessary for regular use of 3 column teasers.

Russell June 20, 2010 at 5:21 pm

Rob, Thanks for the clarification. It makes complete sense to me now.

Nhan July 13, 2010 at 9:34 am

Hi Russell, by any chance you had time to write the jQuery solution for this? Thanks.

Russell July 13, 2010 at 9:52 am

Not yet, however I will spend an hour on it this evening and see if I can get it done

Russell July 14, 2010 at 12:38 pm

Hi Nhan,

Please check out http://www.wordpresswise.com/three-teasers-per-row-without-hacking-thesis-405 for the jQuery solution that involves no changes to Thesis files.

Carol July 24, 2010 at 5:48 am

The site http://www.practicalanalyst.com has a cool feature where teasers are organized in boxes by category (Tools & Techniques section), and this comes out-of-the-box from the wp-clear theme. Do you think to do that in Thesis I’d have to hack the thesis_loop function too? Thanks!

Russell July 24, 2010 at 12:42 pm

Hi Carol,

The Practical Analyst site uses the wp-clear-basic premium theme which has a magazine style for the Home Page.

My approach to this would NOT be to hack the thesis_loop function: I can think of three ways of trying to do this where the amount of work and the level of control both reduce as you proceed down the list:

  1. Create a custom page template that calls query_posts() for each category and grabs the 5 most recent posts you want to feature – with a custom template you have complete freedom of layout
  2. Create a static page for the home page and embed an RSS feed for each category that reads the 5 most recent posts form that category – some simple html around the RSS feed content will produce the required two column layout
  3. Replace the normal home page query by a query_posts() call that returns all the posts you want in the correct order(the full posts first followed by the teaser posts with an even number of teasers in each category to make things simpler) and use the thesis_hook_before_content, thesis_hook_after_content and thesis_hook_before_teaser_box hook to inject the category headings and make the content box into two columns with the teaser box reduced in width using CSS.

I have a client who is planning to move to a magazine style home page in the next couple of months when they have a least 40 items of content of their site. I will use one of these approaches listed above and then report on this blog how I got on. I suspect I will use the second approach which uses RSS as this allows the various magazine sections to include material other than local articles such as tweets, photos from Flickr, news, etc.

Leave a Comment

CommentLuv Enabled

Spam Protection by WP-SpamFree

Previous post:

Next post: