Nick
Nick

Reputation: 35

Multiple WordPress posts in different sections

I'm working on a WordPress website where the front page has multiple blog posts on it, but all with a (slightly) different HTML and also on different places, so just making the loop repeat itself won't do the job.

Design preview:

enter image description here

I was thinking I could maybe make a query for every post and then use 'offset 1', 'offset 2', etc. to query in the right order.

And then after each query reset post data.

Would this be a good method or is this too much load? Any other good solutions?

Thanks!

Upvotes: 1

Views: 47

Answers (1)

Ole Haugset
Ole Haugset

Reputation: 3797

You could do something like this. It will first of all check if there are more posts before it tries to load it. And if there is, you just will get the next story in line to get printed. Just use the if( more_posts() ) where you need to insert a post in your layout

function more_posts() {
     global $wp_query;
     return $wp_query->current_post + 1 < $wp_query->post_count;
}
if( more_posts() ){
    the_post();
    the_title();
}

Upvotes: 1

Related Questions