- This topic is empty.
October 5, 2012 at 3:21 pm #40169
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 :)October 5, 2012 at 3:30 pm #111349SenffParticipant
You can list posts from a certain category just by specifying it in the URL, usually by doing this:
Wouldn’t that be just as easy?October 5, 2012 at 4:33 pm #111350
Of course I have those pages, but now I need to display the posts belonging to that certain category on those pages.October 5, 2012 at 5:13 pm #111351SenffParticipant
Sorry, what I meant was these URLs:
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_OOctober 7, 2012 at 3:06 pm #111387
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?October 7, 2012 at 4:56 pm #111389chrisburtonParticipant
`query_posts( array ( ‘category_name’ => ‘my-category-slug’, ‘posts_per_page’ => -1 ) );`
- The forum ‘Back End’ is closed to new topics and replies.