• Using Hemingway theme, I’m looking to created a page template that show blog posts tagged with a specific category. I’ve already created my template, but currently it’s only pulling from one category, because I’ve set it using:

    `query_posts(‘category_name=sports&posts_per_page=-1′);’

    However, I would need to create a new page template if I created a new page for a different category. So in order to reuse the same page template, I’d like to have code that checks to see the page and category match and show only posts with the category sports and so forth attached to it.

    For Example:

    I have 3 PAGES (Sports, Cars, and Animals), and I have 3 CATEGORIES (Sports, Cars, and Animals). I also have 10 posts for SPORTS, 10 for CARS, and 5 for ANIMALS. When you click on SPORTS on the main navigation on the front page, it should take you to the SPORTS page and show all 10 posts about SPORTS, and so on.

    I also found a post here regarding the same thing, I think… but not sure where to place the code. There’s a code example by user: funkboybilly. Here’s a link to that post: Creating Page Based on Category

    Any help would be greatly appreciated. Thank you guys!

Viewing 1 replies (of 1 total)
  • The easiest way to do this is to use the Categories in your menu. Expand the Categories panel on the left side of the Menus screen, check the Category you want, and click ‘Add to Menu’.

    Another option is to use the Page Links To plugin to link the different Pages to their Category.

    A third way would be to create a Custom Field containing the Category slug. Retrieve the CF and use the value to modify the query.

Viewing 1 replies (of 1 total)
  • The topic ‘Showing Posts on Page based on Categories?’ is closed to new replies.