Let’s say you want to only display posts from a specific category on a page in Thesis. I find myself needing to do this more often than not when creating blogs and websites using the Thesis theme. There is a pretty simple way to achieve this using the special function below.
Here are the 2 simple steps to show posts from a category on a page in Thesis:
- Copy and paste the code below into your
custom_functions.phpfile. You can use an FTP program (My preference is FileZilla), or just use the custom file editor inside of Thesis. - Now add a page or simply use an existing page in WordPress and scroll down to the Custom Field section. Add a new custom field and in the Name field add
custom_cat_page, then in the Value field enter the ID of the category you wish to display. To find the category ID, go to the Post Category section and hover over the category then look at the bottom of the browser window and you will see the ID at the very end of the URL that displays.
The code to insert into your custom_functions.php file:
function custom_cat_page() {
global $post;
$temp_query = $post;
// This loads the data on the current post and saves it in $temp_query (so we can get it later)
$postID = $post->ID;
$custom_cat = get_post_meta($postID, 'custom_cat_page',$single=true);
// Save the custom field 'custom_cat_page' to $custom_cat
if($custom_cat){
// If the custom field is in use...
?><?php
$posts = new WP_Query('cat='.$custom_cat.'&showposts=10');
// Get the 10 most recent posts from the specified categories
while ($posts->have_posts()) : $posts->the_post();
?>
<h3><a href="<?php the_permalink() ?>"><?php echo $post->post_title ?></a></h3>
<?php the_excerpt();
// Show the post title and excerpt.
endwhile;
?>
<p><a href="/?cat=<?php echo $custom_cat;?>">View the Archives</a></p>
<!-- Link to the archives page for the categories -->
<?php
$post = $temp_query;
// Reset $post back to its original content
}
?>
<?php
}
add_action('thesis_hook_after_post','custom_cat_page');
// Add this function after the page's content
You can further customize how you want the posts to display by making the necessary edits to the code. For example, I added post thumbnail functionality so that a thumbnail is shown with each post.
Although you can most likely find similar solutions on numerous blogs, I first discovered this one over at Bill Erickson’s blog. Thanks Bill.
Was this post helpful? Consider subscribing to my blog via RSS or








































{ 27 comments… read them below or add one }
So sad. This is exactly the solution I’m looking for, but I get “Parse error: syntax error, unexpected ‘}’ in /home/content/w/i/t/witcheskitchen/html/wp-content/themes/thesis_16/custom/custom_functions.php on line 32″ message. Any ideas why?
Hi there Linda. I tested this myself and it works. Based on that error it looks like you have a rogue curly bracket ‘ } ‘ in your custom_functions.php file. Could be something to do with how you pasted in the code. Take a look at like 32 and see what happens if you remove that bracket. You’re also welcome to email me the contents of your custom functions file and I’ll take a look at it. Use the contact page.
I’ve looked about everywhere for a solution, but can’t seem to find how to customize the category or tag templates in thesis… sure people tell you how to change the headers and introduction or to create your own page template which is easy, but there’s nothing out there that tells you how to actually wipe out the old tag and category templates and create your own.. any ideas?
Hi Elai. I’ll have to write a tutorial on this one, but in the meantime, it is possible to change the default archive, category and tag pages with the use of Thesis hooks. Here’s 2 links that may be useful for you: DIY Themes Custom Archive Page or Sugarrae’s post on custom category and tag pages. Thanks for commenting.
Yah i’ve read those but those aren’t useful in my case. I’ve done some major Googling and it doesn’t seem that there’s information on how to create a tag / category custom page..
I will wait for your tutorial, in the mean time is there just a basic direction to point me in on how to get started.. im relatively tech savvy…
Awesome tutorial….question, can you explain how to get other post attributes, with your code I was able to get just the post title and excerpt, is there any way to get the headline metadata (author, date, etc…), also exactly how did you get your post thumbnails to display?, thanks so much for your time, this helped alot, im such a beginner at coding.
Hi Jim, thanks for your comment. You can add other WordPress template tags within the loop. So if you want to add the meta information just include the applicable template tag below the title. Visit this page in the Codex to see a list of the available tags: http://codex.wordpress.org/Template_Tags.
For the post thumbnails, follow this tutorial I did on adding featured images (post thumbnails) to Thesis. Then just add the line that references your thumbnails wherever you want within the loop. I use something like this:
<?php the_post_thumbnail( 'THUMBNAIL_HANDLE_HERE', array( 'class' => 'YOUR_CSS_CLASS', 'alt' => the_title('', '', FALSE), 'title' => the_title('', '', FALSE) )); ?>This will make the title of the post as the ALT tag of the image. For more information on featured images, check out this post on post thumbnail images from Mark Jaquith.
Thanks, for your time and patience, I was able find the author and date, code based of the link you provided a simple copy and paste was all that was needed. As far as the thumbnail goes its not so clear, I currently have thumbnails on my homepage posts..they are perfeect, by following the tutorial you suggested will that affect my homepage thumbnails??
Yeah, if you already have thumbnails on your home page, you don’t want to mess with that. I’d just add another thumbnail size like this:
add_image_size( 'image_handle_here', 200, 200, true );.Update the size to whatever you want. The ‘true’ part is saying you want it in hard crop mode. You can leave that out if you want. Either way, add this line in the relevant place in your
custom-functions.phpfile and then you can reference it on your new page using the code from my previous comment above.Hey thanks i am already been using the Tips for some time now
anuj@webtricksblog recently posted..5 Simple Way To Bring Traffic To A Brand New Blog
I have been looking all over the internet for this code for the last month or so. Thank you so much. I tried it and it worked perfectly!
Marian Mangoubi recently posted..Calling All Women Entrepreneurs to Stand Up and Be Counted
Hi there.
I have followed your instructions and it worked apart from the posts are not formatted.
Any reason for this? Is this part of a more global issue?
I would have to see the page you’re referring to in order to comment.
Hi
I have tried doing this in Thesis however cannot find the add a new custom field in my page. Please help.
You probably don’t have the custom field option selected. Just click on “screen options” right at the top of the post edit screen and make sure custom fields is checked.
Thanks for this excellent tutorial. I followed your instructions, and it worked. However, the excerpt is not showing up. I have “Display full post content” checked under Posts in the Design Options area, but even when I switched it to display excerpt, it still did not show up. I only get the title. Any ideas?
Anne recently posted..Sample News Entry
Disregard my question – I figured out what I did. My link in the nav menu was actually a category page in the menu, so I’ll have to switch it to point to an actual page.
Anne recently posted..Sample News Entry
Yes, that’s what I was going to tell you. Glad you figured it out.
hello can you write a guide on placing a feedburner subscription below post like your blog have?
thanks again. great helpful customization blog of thesis themes
anand recently posted..The iPhone 4S: Apple’s Hit Parade Marches On
Sure, I can do that. Just need some time to get it done. In the meantime, a quick tip is just to use the Thesis hook called thesis_hook_after_post. Everything else is just some HTML code and CSS to style it.
i will be looking forward for that post thank you
anand recently posted..The iPhone 4S: Apple’s Hit Parade Marches On
Hi, I wanted to implement this tutorial on my blog because I want thumbnails and excerpts to display in a category page. However, my problem is that in my Thesis 1.8.1 version, the Custom Field section is not available at the end of an editor. There are only tabs for Multimedia Box Video, Custom Multimedia Box Code and Access the Multimedia Box Hook. Terefore I have nowhere to past the “custom_cat_page”. Please help.
creativefashionglee recently posted..How to Wear Pants for a Fabulous Look
You probably don’t have it enabled. Click the “Screen Options” link at the top of the edit post screen, and then make sure there is a check beside the “Custom Fields” option.
Hi, I enabled the custom fields and added the code “custom_cat_page” as well as the category ID. The codes were properly added to the custom-function php too but nothing seems to work.
In my navigation menu, I have all the links of my category pages added as well as their subcategories. i added the each category and subcategory IDs to the custom field but still no changes ocurred. Could you please have a look at my site and see what possibly is wrong?
creativefashionglee recently posted..Style Q&A: What Should I Wear to a Casual Wedding?
If you just want to show posts from a specific category, you don’t need this code. Just link to the category page from your navigation. That’s the archive/category page which will automatically show all posts from the respective category. If you still need to use this method, make sure you have posts assigned to the category in question.
The only instance where it probably won’t work is if you set the page you want to use as the custom category page, as the “blog” page in the WordPress “Reading” settings.
I have posts assigned in each category and they´re showing fine. my only problem actually is how to show thumbnail and excerpts in a list of category. Right now, if you click a category page from my navigation menu, only titles of posts show up, no thumbnails and excerpts.
I thought this code is the solution.
No, this code isn’t supposed to do that. You could use the built in Thesis thumbnail image function or use something like TimThumb as explained in this post: http://thesis-blogs.com/use-timthumb-to-add-thumbnail-images/. If you don’t want to mess with it, I can do it all for you. Just submit the “Hire Me” link at the top of the site.