Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

Morten Korshavn
Morten Korshavn
936 Points

Post snippet for Wordpress!

Hi there!

I wonder if anyone could help me with 2 small problems i'm having in WP.

  1. At my frontpage/landing page in WP i need it to show the 3 latest news fromt the post function. Any snippet of code for that?

  2. Some of my of my other pages at the website, needs to be split into categories. So if you for example visit the "design" page, i'll only need the post from the category design to show up.

Hope someone can help with this small problem.

Cheers!

2 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hey!

First off, you will want to use the WP_Query function for creating a custom loop that only shows the latest three blog posts. Check out this workshop on WP_Query for some more info on specifics.

You can also use this approach for creating custom category listing pages. However, WordPress automatically creates category listing pages for you. Depending on what your URL structure looks like, you should be able to do something like this yoursite.com/category/thecategoryslug and it will automatically generate a page with all of those posts.

In your menu sections in the admin area you can also create links directly to category pages.

Morten Korshavn
Morten Korshavn
936 Points

Hi Zac Gordon !

thanks for the reply (and so quickly, didn't expect that). I'll try to look into the worksho.