Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Getting posts from different categories on different pages

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #40169
    Bob
    Member

    Hi all,

    I’m trying to accomplish something which I think has to do with multiple loops.

    I have a website and I want to have a news section on the homepage. So that would be the latest posts.

    Then, I have multiple pages on which I want to have posts from certain categories. For example, I have a ‘study’ page, a ‘sports’ page, and a ‘work’ page. I’d like to have posts about studying on the study page, about sports on the sports page and of course posts about work on the work page.

    My guess is to have a normal loop on the homepage, and have loops that only display posts from specific categories on the other pages. It wouldn’t matter that much if new posts from one of the pages would also be displayed on the home page.

    However, I have no idea how to do this. I’ve tried things, like specifying from which categories I want to get posts but nothing seems to work.

    Could anyone direct me in the right direction on how to accomplish this? I’d say it’s got to do with multiple loops, and I’ve read things about resetting the loop but I can’t get my head around it. Help would be much appreciated :)

    #111349
    Senff
    Participant

    You can list posts from a certain category just by specifying it in the URL, usually by doing this:

    http://www.mysite.com/study
    http://www.mysite.com/sports
    http://www.mysite.com/work

    Wouldn’t that be just as easy?

    #111350
    Bob
    Member

    Of course I have those pages, but now I need to display the posts belonging to that certain category on those pages.

    #111351
    Senff
    Participant

    Sorry, what I meant was these URLs:

    http://www.mysite.com/category/study
    http://www.mysite.com/category/sports
    http://www.mysite.com/category/work

    I believe that WordPress, by default, uses those URLs to show posts in the categories in question, but you can change that in SETTINGS – PERMALINKS.

    On my own site I don’t need the “/category” part in the URL but I forgot how I did that exactly, or if that was built in in the theme or something…. o_O

    #111387
    Bob
    Member

    Hmm.. could be an option, but I have a menu that is dynamically made by WordPress and I don’t know if (or how) it can include categories as menu items.

    Anyway, I figured it would be easier to create templates for each page… each template with a loop that only get posts from a certain category, and then create pages in the WordPress backend and assign the right template to it. If there’s a better way to do this, I’d like to hear also.

    If not, my original question remains.. so how would those loops look like?

    #111389
    chrisburton
    Participant

    `query_posts( array ( ‘category_name’ => ‘my-category-slug’, ‘posts_per_page’ => -1 ) );`

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.