Aweber - Email Marketing Made Easy
How To Show Posts From a Specific Category On a Thesis Theme Page

How To Show Posts From a Specific Category On a Thesis Theme Page

April 1, 2010 · 27 comments

in Thesis

Thesis 1.x Notice: Thanks for reading this post! So, here's the deal. I wanted you to be aware that this post was written prior to the release of Thesis 2. So that means the instructions or other information provided applies specifically to Thesis 1.x and not the latest 2.x version. Thanks!

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:

  1. Copy and paste the code below into your custom_functions.php file. You can use an FTP program (My preference is FileZilla), or just use the custom file editor inside of Thesis.
  2. 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

This Site Runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced user, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

{ 27 comments… read them below or add one }

Linda Woodrow June 28, 2010 at 10:39 pm

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?

Reply

Thesis-Blogs.com June 28, 2010 at 11:10 pm

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.

Reply

elai August 6, 2010 at 4:16 am

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?

Reply

Thesis-Blogs.com August 6, 2010 at 9:57 am

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.

Reply

elai August 8, 2010 at 6:30 am

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…

Reply

Jim Green September 3, 2010 at 10:30 am

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.

Reply

Thesis-Blogs.com September 3, 2010 at 10:54 am

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.

Reply

Jim Green September 3, 2010 at 11:27 am

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??

Reply

Thesis-Blogs.com September 3, 2010 at 11:46 am

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.php file and then you can reference it on your new page using the code from my previous comment above.

Reply

anuj@webtricksblog March 29, 2011 at 11:12 am

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

Reply

Marian Mangoubi April 12, 2011 at 8:23 am

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

Reply

Andy May 2, 2011 at 9:39 am

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?

Reply

Thesis-Blogs.com May 2, 2011 at 9:55 am

I would have to see the page you’re referring to in order to comment.

Reply

Fols August 24, 2011 at 4:29 am

Hi
I have tried doing this in Thesis however cannot find the add a new custom field in my page. Please help.

Reply

Thesis-Blogs.com August 24, 2011 at 8:57 am

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.

Reply

Anne October 11, 2011 at 10:28 am

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

Reply

Anne October 11, 2011 at 10:40 am

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

Reply

Thesis-Blogs.com October 11, 2011 at 10:53 am

Yes, that’s what I was going to tell you. Glad you figured it out.

Reply

anand October 16, 2011 at 1:34 am

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

Reply

Thesis-Blogs.com October 16, 2011 at 12:48 pm

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.

Reply

anand October 16, 2011 at 6:01 pm

i will be looking forward for that post thank you
anand recently posted..The iPhone 4S: Apple’s Hit Parade Marches On

Reply

creativefashionglee November 1, 2011 at 7:43 am

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

Reply

Thesis-Blogs.com November 1, 2011 at 10:34 am

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.

Reply

creativefashionglee November 4, 2011 at 4:51 am

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?

Reply

Thesis-Blogs.com November 4, 2011 at 7:05 am

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.

Reply

creativefashionglee November 13, 2011 at 4:49 am

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. :)

Reply

Thesis-Blogs.com November 13, 2011 at 9:09 am

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.

Reply

Leave a Comment

When commenting, you can use basic HTML tags. If you are pasting in any code, please escape it here and then include that code within <pre></pre> tags. Thanks!

CommentLuv badge

Next post: