• I’m having some problems trying to display a list of posts onto a page from a specific category. For example, I want to create a page that displays a list of game previews from my site in alphabetical order. I found code and created a Page template in my child theme, but it didn’t display properly. I then searched and found a plugin that would do something similar, but again, it didn’t work as I had hoped.

    Is there a way to create a page that lists the title of posts from a specific category that can then be sorted by name, date, etc? From reading other posts on this topic, it seems like it should be easy to accomplish, but I just can’t figure it out. I wasn’t sure if it’s just me or if it’s something to do with the Hueman theme. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi AZBros. One way to do this would be to set the category in your menu (which would use the default archive.php template), then hide the elements you don’t want to display, then add a “pre_get_posts()” function to your child theme functions.php file to sort the query. Here’s a reference:
    https://codex.www.ads-software.com/Plugin_API/Action_Reference/pre_get_posts

    Or you could copy archive.php to your child theme, rename it to category-unicorns.php (or whatever) and modify that file to display only the title, then add the pre_get_posts() function. That would simplify the CSS since you wouldn’t have to try and hide elements. Here’s a reference on template hierarchy:
    https://developer.www.ads-software.com/themes/basics/template-hierarchy/

    Thread Starter AZBros

    (@azbros)

    I’d like to create a separate page so the Category pages can keep their default look.

    Also, I’d like to add things to the Pages such as a title, featured image and short description. I wasn’t sure if there was an easy way (such as a shortcode) to add a list of links to all the posts in a certain category.

    That way, the main look of the Page remains the same and can be edited when/if needed, but all new posts will automatically be listed on the Page. Right now, on my free WordPress site, I just go in and add links to the posts manually on each Page. It would be nice to have this done automatically, especially once my site gets larger and more authors are submitting posts.

    If something like this is possible, let me know. Otherwise, I’ll see what I can do with the options available. Thanks again!

    If you base your “separate page” on the archive.php template it will include all posts assigned to that page’s category. You can add or remove whatever code you want in the page template as long as you leave the post loop intact. New posts with that category will be included automatically. So if your page template is named “category-unicorns.php”, and you’ve modified the code to only show the post titles, the title (which, by default, is a link to the post) of any post in category “unicorns” will be displayed on that page. Does that help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Posts from Category on Page?’ is closed to new replies.