• frustrated101

    (@frustrated101)


    Hi, I am setting up my new blog… I want 4 different pages to display my posts, sorted by categories.

    What I’ve tried:

    – I DON”T want to auto-generate pages via the menu navigation show categories because I want some other content on the pages too.

    – I also don’t want to add the plug in “posts in a page” because that doesn’t display my posts nicely formatted as they are in my theme.

    What I want to do:

    I’d like to manually create separate page templates (which could be hard coded?) to display only posts from a certain category.

    I’ve tried this tutorial https://www.webmechanix.com/how-to-add-posts-to-pages-in-wordpress-tutorial/ and it seems like I’m on the right track, but the page breaks and just diplays an error message, so perhaps the code isn’t quite right. I followed the instructions exactly!

    I’m sure someone else must have done this… Happy to have a link to another forum topic if anyone has one. Just can’t find this info myself anywhere!

    THanks!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    There are quite a few “posts in a page” plugins. Surely you didn’t try them all.
    The problem with showing a long list in a Page is the pagination. The address for a Page indicates what to get from the database, which is a single Page. Adding a dynamic thing to it is unrelated to the original address. Whereas if you use a category address, it’s all set up for a long list, that shows a few at a time (user setting for how many). The query is already done and the template just outputs it. Pagination works perfectly.

    So, the trick is to inject your “other content” into the existing category template. Most themes output the category description, where you could put whatever you want. You probably have to see if it is output only on the first page or on subsequent pages (very simple). Or you could hardcode your content by making a child theme and specially named templates for the different categories. By hardcoding it, it’s more difficult to edit. If you use the description, that is edited from the Category edit page. There are plugins that add a rich editor for that description.
    Here is the template hierarchy, so you can see what to name your templates for specific categories, if you choose to.
    https://developer.wordpress.org/themes/basics/template-hierarchy/

    Thread Starter frustrated101

    (@frustrated101)

    Thank you for replying, Joy!

    I hadn’t thought about the issue of pagination. I guess using categories in the nav bar could work… but I basically wanted to add a paragraph of text to introduce the category topic, and also, the category display is too narrow, whereas the regular blog post page is full width. Perhaps it’s easier to change the categories template as you suggest. I have checked the link and it looks like I need to find categories.php I don’t have that in my themes folder. Do you know where else I might look?

    Thanks!
    Naomi

    Joy

    (@joyously)

    As I said, you can add a description to any taxonomy, and most themes output it.
    And no, that link does not show categories.php. The correct name is category.php for the generic case, or add a slug on the end for the specific case. And if none of those are present, archive.php is used, and the fallback for that is index.php.
    If your category display is too narrow, is that because it has a sidebar? Because sidebars are good. Otherwise, it’s just a matter of styling, not something you would change in the PHP template.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Manually create a second “posts” page?’ is closed to new replies.