- This topic is empty.
-
AuthorPosts
-
January 13, 2011 at 2:45 am #31235
clockwork
Memberhello all,
my index page has multiple categories on there.. i want each category to display it’s new posts in the corresponding section/list. i’ve looked at codex but the stuff on there is way over my head. can someone walk me through this or have a really simplified site for help?
thanks..
January 13, 2011 at 4:27 am #66209Rob MacKay
ParticipantIf you Google WP Mutipul loops you will find quite a few tutorials on it.
Make sure it is semi recent as some of thing things have changed a little (I don’t think you have to rewind the loop any more)…
here is an intro to the loop too – which is always good to know:
https://css-tricks.com/video-screencasts/91-the-wordpress-loop/
:D
January 13, 2011 at 11:31 am #66145clockwork
Memberthanks robski.
yeah, i see alot of them and some are really old. what would be nice is to actually see it in action in code. i don’t know where the code goes in the page.
January 13, 2011 at 12:44 pm #66148Johnnyb
MemberIt’s just the same as using a single loop except you have more than one! So for example if you wanted 3 columns each with a different category of posts you’d use something like the following:
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif; ?>
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif; ?>
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif; ?>
You just change the category within query_posts to correspond with the ID number of whichever category you’d like to display posts from. Obviously those are very simple loops for the sake of example.
January 14, 2011 at 6:53 pm #65818Rob MacKay
ParticipantJust make sure you reset the query at the end too
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif;
reset_query();
?>
if you don’t I think you basically just add to it instead of starting fresh :)
January 19, 2011 at 10:24 pm #65122cjk
MemberHey Robski, how about the $my_query = new WP_Query() method and the get_post() method? I know the new WP_Query eliminates rewind and reset, I use that on my site to list posts from specific categories on certain related page pages. The get_post() method I haven’t played with yet but apparently it eliminates multiple query issues as well.
As usual though, in WordPress there are numerous ways to get something done and this leads to confusion. I wish I could find an article explaining why and when you would use the different methods!
January 19, 2011 at 10:52 pm #65067mshort1985
MemberChris did a screencast about this a while back, it can be found here. He goes through how to use the loop generally as well as how to make multiple loops on the same page.
August 11, 2011 at 10:54 pm #84877slobjones
MemberRobski, adding your reset_query line results in: “Fatal error: Call to undefined function reset_query()”
I know we need to reset the loop. But what is the correct procedure?
Thanks.
August 12, 2011 at 12:04 am #84882slobjones
MemberAnother question for JohnnyB:
Using your script, how would we prevent duplicate posts?
I’ve tried to apply the appropriate code shown in the Codex Loop discussion, but end up knocking out an entire category instead.
Thanks.
August 12, 2011 at 7:31 am #84887jayme
MemberNice thread guys! We might try to work a reference to this one into our blog post about wordpress houses later next week. You can get answers of all of your queries there. http://juggernautwebsdesign.com/wordpress%5Dwordpress company
August 12, 2011 at 7:40 am #84901Brightonmike
Member@jayme You do know this forums links are nofollow, right? As in, you will gain absolutely NO SEO benefit from posting links in here
August 12, 2011 at 7:51 am #84903krogsgard
MemberActually, you don’t want to use query_posts to do multiple loops on one page. WP_Query is the most versatile solution. The best article on the subject of when / how to use which loop method is actually on CSS-Tricks’ sister site, DigWP.
It really is a must read: http://digwp.com/2011/05/loops/
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.