Today’s quick Thesis Video tutorial will demonstrate how you can easily access Wordpress Custom fields via Thesis Hooks. If you have been exposed to the power of Custom Fields, this tutorial will be great for you. If you haven’t used them you may want to read up on them at the Wordpress Codex. Custom fields are how Michael Gray built his Thesis Carousel and how many other “Premium” Wordpress display special information, such as “featured images.”
Within this tutorial we will guide you through how to use Thesis to display your own “featured images.” In a few weeks we will use this code to build a full featured slider for your theme. Once you have a mastery of Wordpress Custom Fields you can essentially make Thesis do anything under the sun.
Bonus: While recording the video I realized some people may want to only show the hook they are modifying to themselves. So I’ve included this code as well. Remember to add your IP Address or you won’t see the hook either. :) If you want to know your IP Address look in the sidebar.
Please Note This is an Old tutorial. The examples used have changed.
Within this Video we used the following Thesis Hook:
<? function thesis_custom_field_training(){
global $post;
global $more;
$YourIP = array('00.00.00.00','00.00.00.00'); /* Add your IP Address Here*/
if (in_array ($_SERVER['REMOTE_ADDR'], $YourIP)) {
if(is_home()){ //Is the Home Page
$my_custom_query = new WP_Query('showposts=1'); //Custom Query - Find the First Post
while ($my_custom_query->have_posts()) : $my_custom_query->the_post();
$key = 'training_text'; // Our Custom Field Name
$img_array = get_post_custom_values($key); //Holding array
$featuredimage = $img_array[0]; //Assign Value
?>
<img src="<? echo $featuredimage;?>" />
<?
endwhile;
}
}
}
add_action('thesis_hook_before_content','thesis_custom_field_training'); ?>
As explained in the video this hook, accesses the “thesis_post_image” custom field for our most recent post and assigns it to a variable. We then output the variable to the screen.
I am sure you will find this quick tutorial of use, especially if you want to take your Thesis Customizations to the next level.
If you have any questions or comments please leave them below.
Get Free Updates From Art Of Blog
Sign up to receive insider tips only available to our email subscribers.
You can also subscribe to our RSS feed or follow us on Twitter to get the latest updates. Check out our YouTube channel for the latest video tutorials!






Top 25 Tutorials for Thesis Newbies
Two Sure-Fire Ways to Increase Website Traffic
Introduction to Custom CSS in Thesis
Installing and Optimizing Thesis Theme for Wordpress
Thesis Recent Tweets with @Anywhere Integration
Thesis Review: Thesis Wordpress Theme Video Review
What’s in It for Me: 7 Types of Timeless Core Content
{ 4 comments… read them below or add one }
Man… that’s really complicated. I totally lost you with the $my_custom_query = new WP_Query(’showposts=1′); I mean what are you doing there? How are you getting $key or the post-ID?
I think Thesis is a nice WP theme but it’s way to closed off and proprietary to be considered a framework.
Nick,
Thanks for taking the time to write this out. I think I’m missing some basic information because I’m just not getting it. I looked up WP_Query() but again, it’s just over my head (I do know some basic PHP just not WordPress structure). Do you know of any basic (from the ground up) tutorial that goes through this with a simple, step-by-step example? Or perhaps you’d care to make one?
I think you’re gonna make some great tuts man! you’ve ‘got it’. Stick with it.
Daniel,
I would suggest reading these two tutorials. the first goes over the basics of the loop. (the core code that makes Wordpress display posts). The second one goes into detail on how to create custom loops, which is what we use in this tutorial.
http://www.themelab.com/2008/04/04/the-ultimate-guide-to-the-wordpress-loop/
http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/
Hope this will make things a little more clear, if it isn’t i’ll try and make a tutorial explaining the loop.
Daniel,
I’ll do my best to explain what is going on here. Like I mentioned I’m no php guru, but I get it a bit.
Essentially where we define a custom query starting with the line “my_custom_query” we ask wordpress to give us the most recent post. This takes the place of the post id.
The while statement will walk through this post (and more if you queried more) and do whatever is between the begin “while” and the “endwhile.”
In this example we are looking to get the custom wordpress field “thesis_post_image” which is where thesis stores the information on the post image you upload. $key is the name of the custom field you are using.
What we do then is use the wordpress query “get_post_custom_values” for the key. This will return as an array. Of this array we want the first entry and we asign it to $featuredimage. We then echo out the featured image.
Hope this makes it a bit clearer, that video was recorded VERY quickly with no rehersal or plan, I wanted to get it out and was pushed for time.
Let me know if you have more questions.