Tutorials

Rockin’ out WordPress custom loops

25 February 2010 · 53 comments · tagged with , , , , ,

What’s a loop?

When using WordPress, “The Loop” refers to the code in your template files that displays posts. Usually there is only one main loop per page, but you can have secondary custom loops to show special content. These can include recent posts and related posts.

The loop depends on queries

A query is related to the loop in that it determines what should be shown in the loop. For example, the default home query will contain all posts, 10 per page (or whatever number is set in Settings > Reading), from all categories; a single post query contains only information for the post or page you are viewing; archive loops will have posts according to the kind of archive page you are on (category, tag, month etc).

Default and custom queries

The main query for a WordPress page is determined automatically by the type of page you are viewing (it’s all handled by WordPress). You can create a custom query out of the default query by using the following PHP code somewhere before the start of your main loop code.

global $query_string;
query_posts($query_string . '&cat=-5');

The above code gathers the variable $query_string, which contains all the default query information and then uses query_posts() to create a query with all of the features of the default query, except the attributes that you change. In the example I have excluded the category with an ID of 5 from the query.

The benefit of using $query_string in this way is that you don’t destroy page pagination on the home and archive pages, which will happen when using query_posts() by itself.

The Loop code

The main loop code generally starts with something like <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>. Where have_posts() is a WordPress function that determines whether the current query has any posts in it. while ( have_posts() ) says “as long as there are posts in the query, do the following things”, and this repeats for each post until there are no more. In this case “the following things” are to execute the function the_post(), which fetches the post data from the database and makes it accessible for use via Template Tags, some of which are only available inside the loop.

Creating a custom loop

If you which to access other posts (to create a recent, related, popular or featured post list, for example) while keeping the main loop in tact you need to create a secondary custom loop. The best way to do this is to create a new query, using the WP_Query() function, which will be completely separate from the main query. Then you may loop over the posts in your new query.

New query for the custom loop

WP_Query() accepts the same parameters as query_posts(), so have a look at that Codex page to find out what parameters you need.

For this example, let’s query 5 random posts from a category called “Featured”.

$custom_loop = new WP_Query('showposts=5&category_name=Featured&orderby=rand');

Custom loop code

Now we have to loop over the posts in the new query. Since the original page query still exists and our new query is stored in the variable $custom_loop we can’t use the same code as the main loop, but it is similar. This loop is basically the same as the main loop code, but it checks our custom query variable $custom_loop for the posts.

if ( $custom_loop->have_posts() ) :
	while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

		// this is where we put the code to show what we want for each post

	endwhile;
endif;
Content for the custom loop

Unless we replace // this is where we put the code to show what we want for each post with something, nothing will actually show up when we run this code.

One of the simplest (and useful) things we could do is create a list of linked post titles.

if ( $custom_loop->have_posts() ) :
	echo '<ul>';
	while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

		echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';

	endwhile;
	echo '</ul>';
endif;

Note that because the code between while and endwhile gets repeated for every post, <ul> and </ul> (which start and end the unordered list) need to go outside of that part, i.e. outside of the loop.

Putting it all together

The complete code for a custom query and custom loop producing an unordered list of random featured post title link is:

$custom_loop = new WP_Query('showposts=5&category_name=Featured&orderby=rand');
if ( $custom_loop->have_posts() ) :
	echo '<ul>';
	while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

		echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';

	endwhile;
	wp_reset_query();
	echo '</ul>';
endif;

This is all PHP code, so make sure that you are in a PHP environment, i.e., this code should be somewhere after <?php and before ?>. If these bits aren’t in your file where you want the custom loop to go, you can wrap the code in them.

Towards the end I’ve added wp_reset_query(), which — as the name suggests — resets the query. For some reason, when using new WP_Query(), endwhile ends the loop, but not the custom query. There’s another method on The Loop codex page, but it hasn’t always worked for me.

Sometimes I find that wp_reset_query() doesn’t quite work the way I want it to, I don’t get back to the original query. If you have that problem try if ( have_posts() ) { while ( have_posts() ) { the_post; } };. That usually works for me to reinitiate the original loop, but I’ve seen it create a recursive post loop too, so be careful.

Using the custom loop in Thesis

Using the custom loop in Thesis is pretty simple (once you have a grasp on the less simple stuff above): all you have to do is wrap the above code in a function and hook it in. If you need more info on basic function syntax check out What are hooks and how do you use them? and The basic anatomy of a custom function on the Tech for Luddites blog.

function custom_featured_posts() {
	$custom_loop = new WP_Query('showposts=5&category_name=Featured&orderby=rand');
	if ( $custom_loop->have_posts() ) :
		echo '<ul>';
		while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

			echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';

		endwhile;
		wp_reset_query();
		echo '</ul>';
	endif;
}
add_action('thesis_hook_after_post','custom_featured_posts');

That code pasted into custom_functions.php will add a list of 5 random posts from a category called “Featured” to the bottom of every post.

If you only wanted to show it on single post pages you would use a conditional tag by adding if ( is_single() ) : after the first line that opens the function, and endif; before the last curly bracket that ends the function.

Add it to the sidebar

If you want to add it to the sidebar to look like your other sidebar widgets you can use the following function.

function widget_featured_posts() {
	$custom_loop = new WP_Query('showposts=5&category_name=Featured&orderby=rand');
	if ( $custom_loop->have_posts() ) :
		echo '<li class="widget widget_featured_posts">';
		echo '<h3>Featured Posts</h3>';
		echo '<ul>';
		while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

			echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';

		endwhile;
		wp_reset_query();
		echo '</ul>';
		echo '</li>';
	endif;
}
add_action('thesis_hook_before_sidebar_1','widget_featured_posts');

The function has the widget code and a heading added to match the HTML format of widgets in Thesis.

How about using thumbnails instead of post titles?

Using thumbnails is a bit more attractive and intriguing than a list of post titles (not that a good post title can’t pull people in). If you use Thesis you should know about Post Images and Thumbnails; if you don’t please watch the in-post options video!

There’s a nice little snippet of code that you can use (inside the loop) to fetch the thesis post image or thumbnail:

$post_image = thesis_post_image_info('thumb');
echo $post_image['output'];

Use this in your custom loop like so.

function custom_featured_posts() {
	$custom_loop = new WP_Query('showposts=5&category_name=Featured&orderby=rand');
	if ( $custom_loop->have_posts() ) :
		echo '<strong>Featured Posts</strong>';
		echo '<ul class="featured_posts">';
		while ( $custom_loop->have_posts() ) : $custom_loop->the_post();

			$post_image = thesis_post_image_info('thumb');
			echo '<li>' . $post_image['output'] . '</li>';

		endwhile;
		wp_reset_query();
		echo '</ul>';
	endif;
}
add_action('thesis_hook_after_post','custom_featured_posts');

$post_image['output'] has the whole linked image markup with classes etc. If you just want to fetch the thumbnail URL to add your own HTML around it, use $post_image['url'].

The following CSS (to be placed in custom.css) will cause the thumbnails to be displayed horizontally next to each other.

ul.featured_posts {list-style:none;}
	ul.featured_posts li {float:left;}

A related posts query

There are several ways to determine if a post is related to another post, without getting too crazy with it, the simplest and most obvious attributes to use are categories and tags. If you haven’t been using categories and tags on your blog I would say to find a plugin that uses other means to determine relatedness, and don’t try to write your own related posts query (if you’re able to write one not based on categories and tags you probably don’t need this tutorial anyway!).

function custom_related_posts() {
global $post;
if ( is_single() ) :
	//stores the original post data
	$original_post = $post;

	//get the post category
	$category = get_the_category();
	$cat = $category[0]->cat_ID;

	//gather a list of tags
	$tags = wp_get_post_tags($post->ID);
		$taglist = '';
		if ($tags) {
			foreach ($tags as $tag) {
				$taglist .= $tag->term_id . ',';
			}
			//start loop and query stuff
			$args = array(
				'cat' => $cat,
				'tag__in' => array($taglist),
				'post__not_in' => array($post->ID),
				'showposts'=> 5,
				'caller_get_posts'=> 1
			);
			$related_posts = new WP_Query($args);
			if ( $related_posts->have_posts() ) :
				echo '<ul class="related_posts">';
				while ( $related_posts->have_posts() ) : $related_posts->the_post();

					$post_image = thesis_post_image_info('thumb');
					echo '<li><a class="post_image_link" href="' . get_permalink() . '" title="Permanent link to ' . get_the_title() . '">' . $post_image['output'] . '</a></li>';

				endwhile;
				wp_reset_query();
				echo '</ul>';
			else :
				echo '<p>Sorry, no posts found</p>';
			endif;
		}
endif;
}
add_action('thesis_hook_after_post','custom_related_posts');

This adds a list of linked thumbnails of related posts to the bottom of a single post page. I’ve added a couple of comments in there to indicate what’s happening in the code.

The $args = array(... syntax is just another way of writing out the parameters to use in WP_Query(). It can be a bit easier for humans to read when using more than a few parameters to put them into an array like that.

The tag__in parameter indicates that the related post should be tagged with any (but not necessarily all) of the same tags as the current post. post__not_in is used here to exclude the current post from the query. caller_get_posts, when set to “1″, means that sticky posts are excluded.

You may notice that I’ve added a link around $post_image['output'] because the whole function will only be shown on a single page, but $post_image['output'] doesn’t output a link on single posts and pages.

Questions?

If you are not sure which WordPress tags to use in your loop or parameters in your query, please check the WordPress codex before asking here:

If you need clarification on a particular bit of the code or it doesn’t work in a particular situation, please let me know and be specific. Thanks!

{ 47 comments… read them below or add one }

1 Oscar February 26, 2010 at 02:16

What a great article. It clarifies a lot of things that I didn’t quite understand before. As always, thanks for such a great and through article!

2 Marco February 27, 2010 at 00:59

That’s a great post. Useful. Bookmarked!

3 Erick Patrick February 27, 2010 at 01:59

Each and everyday, friends of mine ask me to clarify the loop in WP to them. Now, I know where I can send them and get a little more free time \o/

4 Randa Clay February 27, 2010 at 06:20

Thanks for this awesome, clear overview of this functionality. I use it regularly, but I love your related posts idea, along with the thumbnails- very nice.

5 Rilwis February 27, 2010 at 19:41

This is not new, but it’s detailed. Good article for reference. Thank you.

6 Greg Nemer February 27, 2010 at 23:16

Hi Kris,
You’re going to get a lot of bookmarks with this article since it is so handy to refer to.

You have a real talent for explaining everything in very good detail.

Thanks,

7 Kate Foy March 4, 2010 at 11:57

Thanks Kris. Great tutorial post as always, and most helpful in coming to grips with the loop! It’s stashed away in Delicious!

8 Marc Deschamps March 9, 2010 at 16:59

Great post, i’ll use what i learned here in my actual custom theme for sure!
Thanks :-)

9 Craig Sunney March 22, 2010 at 03:56

This looks really low key the way you’ve presented here, but it’s kind of like the Holy Grail from an SEO perspective on creating proper site interlinked (themed) areas. You’re really made it easy to follow. Thanks Kristarella :)

10 Scott May 3, 2010 at 09:24

I got the relate posts script to work but I can’t figure out how to style it to look like my current related posts plugin. If you look at any of my blog posts you can see that the related posts are side by side with the title below the image. Is something like this not going to be possible without the plugin?

11 kristarella May 3, 2010 at 14:21

Scott — You can do that with this query. The CSS is something like

.custom ul.related_posts li {float:left; width:22%; margin:0 2% 1em 0; list-style:none; text-align:center;}
  .custom ul.related_posts li a {display:block;}
  .custom ul.related_posts li a img {display:block;}

Then to add the title in you change the line

echo '<li><a class="post_image_link" href="' . get_permalink() . '" title="Permanent link to ' . get_the_title() . '">' . $post_image['output'] . '</a></li>';

to

echo '<li><a class="post_image_link" href="' . get_permalink() . '" title="Permanent link to ' . get_the_title() . '">' . $post_image['output'] . get_the_title() . '</a></li>';
12 Scott May 3, 2010 at 21:17

That worked perfect. I was totally using the wrong CSS class. I forgot to put custom before related_posts and didn’t think to put ul.

The only thing I notice is that for some posts it shows a bunch of related posts but on some it only shows 1. like my project 365 photos, there are a bunch in the same category but it only shows 1 as related. that’s because of the tags being different?

13 kristarella May 4, 2010 at 10:07

Scott — Yes, it’s probably because there are not more posts with those tags. You could tweak the way the query defines “related” to only us the category or something if you wanted. Since everyone uses categories and tags differently and writes differently it’s hard to specify one function that will work just right for everyone (without getting more complicated and trying to match words in post content etc).

14 Scott May 4, 2010 at 11:03

That’s what I figured. Thanks!!

15 Umesh May 29, 2010 at 04:21

Hi, thanks for the very informative post. I wanted to lists the 5 most recent posts on the index page based on category they fall under, but I want to control the order of appearance of categories. Any suggestions for the best strategy to implement this?

16 kristarella May 29, 2010 at 20:35

Umesh — I would use get_categories() to gather the categories that you want (by using the include or exclude parameters) and in the order you want (by using the orderby parameter) then create a new WP_Query loop for each of the categories. The basic outline of the code would be:

$categories = get_categories('include=1,2,3,4&orderby=name');
foreach ($categories as $cat) {
	$recent_post = new WP_Query('showposts=1&cat=' . $cat->term_id);
	while($recent_post->have_posts()) : $recent_post->the_post();
		HTML AND PHP FOR THE POST GOES HERE
	endwhile;
	wp_reset_query();
}

Or if you can’t order them the way you want using the orderby parameter (or if you don’t need to access any other category information in the loop) you could manually create an array of category IDs. E.g., $categories = array(1,2,3,4); — the foreach would then cycle through those four category IDs and you would just use $cat instead of $cat->term_id in the query.

17 Umesh May 29, 2010 at 21:20

Thank you very much Kristarella.

18 Rick Anderson June 22, 2010 at 23:12

Wow, that is a very well written and detailed post. Those are excellent examples of how to use wp_query in the context of Thesis. I hadn’t really thought of this before but you could easily use your code to produce a “gallery” of thumbnail images that link back to their posts. – For example, you could use it as a catalog page where each product is a post and the traditional “grid view” of products is produced with your custom query.

Thanks again for all of your contributions to the community.

19 kristarella June 22, 2010 at 23:15

Rick — Cheers! Yeah, the gallery thing is pretty much exactly what I’m doing with my photoblog archive. Man, I love custom queries!

Thanks for all your contributions in the forum! Great to see people helping each other out!

20 Jason Coffee June 23, 2010 at 02:06

Maybe you covered this but Is there a way to “call” it on a page so I could add it to my static home page. I would like it to appear in the table next to each video in each category as a list of most recent posts for each category.

21 kristarella June 23, 2010 at 09:44

Jason — You need to use Conditional Tags. If you’ve created your home page manually in the WordPress editor you can’t really integrate this in the middle of the page, you’d need to copy the contents of your page into custom_functions.php and then add a loop for each category where you want it. Then you wrap the whole contents inside the function with if (is_front_page()) { ... } and hook it in with thesis_hook_after_post.

22 kay July 3, 2010 at 00:35

I love how you explain this stuff. Really helps shorten the learning curve.

I’m really curious as to how they coded their home page for the three featured posts on ArtofBlog
http://www.artofblog.com/

I am wanting to do something similar for my home page but having a hard time wrapping my mind around how I’d get it to work.

thanks!

23 kristarella July 3, 2010 at 17:56

Kay — Art of Blog has a custom full-width area (similar to the full-width nav area in my full-width headers tutorial), which I suspect contains 3 custom loops getting a post from 3 different categories. I’m not sure whether these are the most recent posts from those categories, or ones tagged with something, or some other way to select them.

You can use the code I showed in this tutorial to get the Thesis Post Image thumbnail, although you can see that their post thumbnails are a different size to the images in the 3 featured posts: they are actually using the WordPress featured image for those particular posts (slightly more complicated to explain, I would go with the Thesis thumb if it suits what you’re trying to do).

24 Cassie July 7, 2010 at 13:10

Hi Kristarella,

It took me a few reads but I think I get the concept!

I loved how you did your photoblog archive. I’m a CSS newbie so can you explain how to create the grid like you did?

Thanks!

25 kristarella July 7, 2010 at 14:47

Cassie — The photoblog archive is an unordered list of linked images (using the Thesis thumbnail code, like the above tutorial). To get it in a grid you can simply float all the list items to the left and they will stack together. The minimum CSS you’d need is

ul li {list-style:none; float:left; margin:0.5em;}
26 Cassie July 7, 2010 at 14:54

Thank Kristarella! I’m thinking about using it as a way of displaying three teasers across my content area. Instead of calling a thumbnail I would call the teaser. Essentially it’d be an unordered list of teasers. Not sure if it’ll work but am going to give it a try.

27 kristarella July 7, 2010 at 23:25

Cassie — If you’re looking into implementing custom Thesis teasers (and if you want them to use the same format as the usual Thesis teasers), check out this forum thread for a thesis teaser custom loop.

28 Cassie July 8, 2010 at 00:39

Thanks for pointing out the thread. I don’t really understand the code or if that’s what I’m looking to do but I’ll give it a try. I basically just want three teasers to show on the home page, side by side, like three columns. Seems to be a hard thing to come by!

29 kristarella July 8, 2010 at 11:14

Cassie — That code won’t do three automatically, but could with a little adjustment. Anywho, good luck, and feel free to ask in the forum thread if you need help with it.

30 Martin August 1, 2010 at 03:41

Make a css div from 100% x 100% div containing all of the site could accommodate any screen resolution?

31 Mark August 1, 2010 at 04:41

Thanks for your as always very clear tutorial.

I am trying to put out the title and the except in the same formating as I would normally have in Thesis. But nothing is coming out styled. Following is my code. Could you tell how I could go about that?

function reviews_page() { if (is_page(array(584,’999′))) {$query = array ( ‘posts_per_page’ => 10, ‘cat’ => 84);$queryObject = new WP_Query($query);// The Loop…if ($queryObject->have_posts()) { while ($queryObject->have_posts()) { $queryObject->the_post(); the_title(); the_content(); }}}}remove_action(‘thesis_hook_custom_template’,'thesis_custom_template_sample’);add_action(‘thesis_hook_custom_template’,'reviews_page’);

32 Mark August 1, 2010 at 04:42

Sorry about the code above, I used the encoding link you specified and I’m not sure what happened…

33 kristarella August 2, 2010 at 00:03

Mark — You need to add the HTML that goes around the post elements, like the following (inside the loop):

$queryObject->the_post();
?>
	<div class="headline_area">
		<h2><?php the_title(); ?></h2>
	</div>
	<div class="format_text">
		<?php the_content(); ?>
	 </div>
<?php

Sorry about the encoder. At some point they made it a default option to encode line endings, which is just unnecessary and ugly in this context, I’ll have to find a different encoder to link to.

34 Mark August 2, 2010 at 01:07

Thanks a lot, Kristarella.

35 Mark August 2, 2010 at 04:57

Well, I did as you suggested, and while the data to the page, it still does not pick up the styling. Is it confused because it’s a list of posts within a category, shown on a Page?

36 Mark August 2, 2010 at 05:08

I figured it out. It needed a bit different div and class stuff. Here is what works.

(I hope I paste this in without screwing up your comment again:

37 Mark August 2, 2010 at 05:10

<div class="left_wp_thumb">
<?php
the_post_thumbnail();
?>
</div>
<div class="headline_area">
<h2 class-"entry_title">
<?php
the_title();
?>
</h2>
</div>
<div class="format_text entry-content">
<?php
the_excerpt();
?>
</div>

38 Amy August 25, 2010 at 13:47

Hi, thank you so much for this post. I have been wanting to put thumbnails (only) in a sidebar widget so I used your example loop for creating thumbnails.

I’m experiencing a curious behavior, though. The thumbnails are linked only on the home page, but none of the posts or pages. Why would $post_image['output'] only output the linked markup on the home page only? Hmm…

The other pages just show unlinked thumbnails.

Thanks!

39 kristarella August 25, 2010 at 14:20

Amy — Ugh, yeah, I’ve noticed that when using the thumbnail code sometimes too. I’m guessing that there’s a conditional statement in the code for thumbs saying “only show the link on home and archive pages”. I don’t know if that was always the case, or just recent behaviour. If it’s causing problems, try something like:

echo '<a href="' . get_permalink() . '"><img src="' . $post_image['url'] . '" alt="' . get_the_title() . '" /></a>';

40 Andy August 27, 2010 at 21:26

Hi I was wondering if you could use queries to render posts grouped in the year they were posted.. Like so,

2010
Post Title
Post Title

2009
Post Title
Post Title

Have been looking everywhere for some help for this seemingly simple function, was wondering if you knew how to, without using plugins..

Cheers!

41 kristarella August 31, 2010 at 11:28

Andy — I started to look for a solution for you and then I got distracted by work…

In theory it wouldn’t be too hard to do what you need; the main problem I’m finding with it is that there is no function built into WordPress to help us figure out which years have posts in them. So, I had to get the first and lasts posts from the blog, get their years and go from there…

function custom_posts_by_date() {
	$first_post = get_posts('showposts=1&orderby=date&order=ASC');
	foreach ($first_post as $post)
		$first_year = substr($post->post_date, 0, 4);
	$last_post = get_posts('showposts=1&orderby=date&order=DESC');
	foreach ($last_post as $post)
		$last_year = substr($post->post_date, 0, 4);

	$years = range($last_year, $first_year);
	foreach ($years as $year) {
?>
		<ul>
<?php
			$year_posts = new WP_Query('showposts=-1&year='.$year);
			if ($year_posts->have_posts()) {
				echo '<li><h3>' . $year . '</h3><ul>'."\n";
				while ($year_posts->have_posts()) : $year_posts->the_post();
					echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'."\n";
				endwhile;
				echo "</ul></li>\n";
			}
?>
		</ul>
<?php
	}
}

Hook that function to where you want it and it should work, with a bit of styling to make it pretty.

42 Andy August 31, 2010 at 18:26

Hey Kristarella, thanks for your efforts! ill give it a go this afternoon! im practically useless at php but a snippet like this will get me going for now! Thanks again!

43 Dan Harrington September 1, 2010 at 03:12

Hi Kristarella,
I have a static homepage where I’d like to display a list of recent posts underneath my content. I know nothing about PHP so I’m just wondering if one of the snippets of code above would work for me? Thanks so much for your time. Here is the site I’m working on:
http://balihealer.com/

44 kristarella September 1, 2010 at 10:12

Dan — The example query and loop code I’ve given will work to give you the 5 most recent posts if you delete &category_name=Featured&orderby=rand from the query.

45 Dan Harrington September 3, 2010 at 01:14

Hi Kristarella,
Thanks, but that doesn’t seem to work either. I think my issue may be that I’m using a custom template, so the hooks don’t work on the static page. Here is the code from my template:

<?php
/**
* Template Name: Homepage
*/
?><head>
<link rel="stylesheet" href="http://balihealer.com/wp-content/themes/thesis_17/style.css?082310-161521" type="text/css" media="screen, projection" />
<link rel="stylesheet" href="http://balihealer.com/wp-content/themes/thesis_17/custom/layout.css?082310-161419" type="text/css" media="screen, projection" />
<!–[if lte IE 8]><link rel="stylesheet" href="http://balihealer.com/wp-content/themes/thesis_17/lib/css/ie.css?082310-161437" type="text/css" media="screen, projection" /><![endif]–>
<link rel="stylesheet" href="http://balihealer.com/wp-content/themes/thesis_17/custom/custom.css?082310-161417" type="text/css" media="screen, projection" />
</head>

<div id="container">

<div id="page">
<div id="social-eat-pray-love">
<a href="http://www.facebook.com/group.php?gid=134775876562044" target="_blank">
<img src="http://www.balihealer.com/bali-healer-images/facebook-logo.png" width="35" height="35" /><br />Follow us on Facebook</a></div>

<div id="social-eat-pray-love-2"><a href="http://twitter.com/Ketut_Liyer" target="_blank">
<img src="http://www.balihealer.com/bali-healer-images/twitter-logo.png" width="35" height="35" /><br />Follow us on Twitter</a></div>
<?php echo thesis_nav_menu(); ?>
<?php echo thesis_header(); ?>
<div id="ketut-liyer-photo">
<object width="500" height="405"><param name="movie" value="http://www.youtube.com/v/7o_vBqIoM08?fs=1&amp;hl=en_US&amp;color1=0x3a3a3a&amp;color2=0×999999&amp;border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/7o_vBqIoM08?fs=1&amp;hl=en_US&amp;color1=0x3a3a3a&amp;color2=0×999999&amp;border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="405"></embed></object>
</div>

<div id="content_box">
<div id="content">
<div class="content-column">
<div id="ketut-liyer">

<h1>About Ketut Liyer: A Healer in Bali</h1>

<p>In 1997, a young American filmmaker, fluent in the Indonesian language, returned to Bali to explore the world of Balinese healers.</p>

<p>Over many months, he filmed interviews with several legendary traditional healers â?? called â??Balianâ?? or â??dukunâ??. He also interviewed their patients and several experts â?? Balinese and Western â?? in order to better understand the world of Balinese medicine. His unprecedented access to these healers â?? living in their homes â?? participating in ritual events â?? allowed him to document many remarkable events and healing sessions.</p>

<p>One of the healers was Ketut Liyer, who became a major character in Elizabeth Gilbertâ??s best-seller â??Eat, Pray, Loveâ??. The footage depicts a man somewhat different than the character described in Gilbertâ??s book. In the footage, Liyer is in excellent health and at the height of his mental and spiritual powers. The interviews â?? conducted in Indonesian with English subtitles, reveals an articulate man with a steely intelligence, who can speak with great authority on the subject of Balinese healing and what is called sikala and niskala â?? the seen and unseen â?? that effect health.</p>

<p>Ketut Liyer, traditional healer, Elizabeth Gilbertâ??s healer from Eat, Pray, Love.</p>

</div>

</div></div>
<div class="sidebars">
<?php echo thesis_sidebars(); ?>
</div>

<?php echo thesis_footer_area(); ?>
</div>
</div>
</div>

46 Dan Harrington September 3, 2010 at 01:45

Not sure if that code will help much, I put it through the encoder but it looks a little garbled. I posted it on the Thesis forums here:

http://diythemes.com/forums/showthread.php?36608-Tutorial-Static-Front-page-with-paginated-posts-%28Loop-API%29

Thanks so much for any suggestions. My guess is that the template file is causing the hook system to break somehow, I’ve tried about 10 different solutions to call in posts using the customfunctions.php file and none of them work. The question would be what is structured wrong in my template file?

47 kristarella September 3, 2010 at 10:23

Dan — Hooks are PHP functions within the page structure. If you rewrite the whole page, which is essentially what you’ve done with the page template, you will lose some or all of the hooks (you’ve probably still got sidebar hooks since you’re not rewriting those bits).

Page templates (in this form) are not really the right way to work with Thesis. Unless you really want to use a page template because it’s going to be implemented across many pages, the best way is to use custom templates. Take a look at Berchman’s tutorial on that. However, from what I can see of your page template, I see no reason why you’d need a page template in this case, I think what you want to do is:

  • Set the page as the static home in WordPress Reading settings
  • Set the page to the default template
  • Paste the main contents of the page into the edit page box
  • Activate the feature box from the Thesis Design Options to display on the home page and hook the video you’ve got above the content into the feature box
  • Hook recent posts after the home page contents

That’s about it give or take a bit of fine tuning.

If you really want to stay with the page template thing, don’t try to hook the recent posts in, paste it in the page template.

Leave a Comment

Want to show PHP or XHTML code in your comment? Encode it first so that WordPress doesn't strip it away.

Read the comment policy.

Previous post:

Next post: