I'm trying to create the actual "blog" page that lists all the posts. It seems like such a basic thing, but i can't find out how to do it.
Do i create a page and assign it a special template? If i do that, wouldn't the loop just grab the page content? I have a loop in a file called loop.php, which i want to use to display the posts.
I tried doing something like this:
- Create a page
- Assign "blog" template to page
- From the blog template, run
get_posts();
which gets all posts. - Right after that, run
setup_postdata()
- Then just
require('loop.php');
to list all posts.
Unfortunately, that just grabs the first post; not what i want.
Any suggestions?
EDIT
A dummy solution would be to do something like:
$posts = get_posts();
foreach($posts as $post) {
setup_postdata($posts);
require('loop.php');
}
wp_reset_postdata();
The only problem is adding pagination, which i will need.
get_posts()
.loop.php
. Look at my example above, that should work.require('loop.php')
it works? (Also, you may want to use theget_template_part()
function to include template files.)