- This topic is empty.
-
AuthorPosts
-
February 9, 2011 at 5:20 pm #31566jacorreParticipant
Hello,
I have a static homepage using multiple loops to display each category with 3 random post entries. I’m using something like the following:
But because I have 12 categories, I’m using 12 query post loops to generate the content. I was wondering if there was a more efficient way of doing it? Thank you!
February 10, 2011 at 3:58 am #61433BobMemberThe second line in your code, this one:
has a deprecated parameter (showposts) in it, according to the query_posts function reference. Try using posts_per_page=3 instead of showposts=3.
That should display 3 posts per page, but I think those will be just the last 3 ones, instead of 3 random ones like you want. Worth to try though.February 10, 2011 at 9:58 am #61366JohnnybMemberI don’t think that’s what he’s asking, what he has should give 3 random posts from a category but he had to use that query post function with each loop 12 times, once for each category. I don’t know whether there’s a way to achieve this with just 1 loop/query post – I haven’t seen anything while browsing the codex, but if someone else has a solution then I’d be very interested to hear it too!
February 10, 2011 at 10:06 am #61368jacorreParticipant@Bob I’m not having a problem with it displaying 3 random posts using showposts. But I probably should switch to using the non deprecated call. Thanks!
@Johnnyb Yes I’m wondering if there’s a way to use one loop to do it all, instead of 12 separate loops. The homepage does 143 queries in just under 2 seconds. At least that’s what I’m getting for the output using:queries. seconds.
But if one loop could be achieved would it make it quicker?
February 13, 2011 at 6:41 pm #60671jacorreParticipantHow about a different question?! When using multiple query_posts loops, should you use the wp_reset_query after each one? I haven’t used it and see no issues. What benefit does it have?
February 13, 2011 at 6:48 pm #60672VinnixMemberI don’t know if I’m talking out of my bum on this, but im n00bish to PHP, are while statments safe from web damages? Like I mean is their anyway your having some type of try-catch for queried calls?
Logically I would do a function to grab the row count for each query then random count something and print out the random numbers…
I’m sure it’s not helpful but just a thought!
February 24, 2011 at 4:03 pm #58493jacorreParticipantI wanted to come back to this topic and get some feedback. I was reading on WordPress that if you’re using multiple loops you should use get_posts instead of query_posts.
What does everyone think? Is one better than the other?
February 24, 2011 at 8:30 pm #58407Historical Forums UserParticipantI can’t answer that, but I would like to know the answer. I myself have a question on looping and was wandering if any of you could take a look at it & give me a response. I was thinking I might find the answer her…
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.