admin管理员组文章数量:1023273
I'm making my first Wordpress theme and I've faced an issue lately.
I have a template file page-event.php
. I intend to use it to answer the /events
path (I have also created an events page). This works at the moment, but I want to make the events template loop through all the posts in categories events
.
For some reason, this doesn't work. When I use the loop in the page-event.php
template, it brings up only one post named events
. I don't know why this happens.
I think it's showing just the category holder for events.
My question is
- Isn't it possible to use the Wordpress loop to loop posts in any template file?
- Why does the code loop through categories instead of posts?
Here's a look through my code in my page-events.php
<?php get_header();?>
<?php
if(have_posts()){
while(have_posts()){
the_post();?>
<p><?php the_title();?></p>
<?php }
}
wp_reset_query();
?>
<?php get_footer();?>
I expect this code to at least provide a simple list of all the posts on the blog, but it returns a single category with the name events
.
Thanks in advance.
Update.
I recently echoed out the $query_string
variable to see what Wordpress was doing, it returned pagename=events
. So it turns out Wordpress is only searching for pages because the page-event.php
was a post type of page.
Need more help on how to make the loop search for posts instead of pages.
I'm making my first Wordpress theme and I've faced an issue lately.
I have a template file page-event.php
. I intend to use it to answer the /events
path (I have also created an events page). This works at the moment, but I want to make the events template loop through all the posts in categories events
.
For some reason, this doesn't work. When I use the loop in the page-event.php
template, it brings up only one post named events
. I don't know why this happens.
I think it's showing just the category holder for events.
My question is
- Isn't it possible to use the Wordpress loop to loop posts in any template file?
- Why does the code loop through categories instead of posts?
Here's a look through my code in my page-events.php
<?php get_header();?>
<?php
if(have_posts()){
while(have_posts()){
the_post();?>
<p><?php the_title();?></p>
<?php }
}
wp_reset_query();
?>
<?php get_footer();?>
I expect this code to at least provide a simple list of all the posts on the blog, but it returns a single category with the name events
.
Thanks in advance.
Update.
I recently echoed out the $query_string
variable to see what Wordpress was doing, it returned pagename=events
. So it turns out Wordpress is only searching for pages because the page-event.php
was a post type of page.
Need more help on how to make the loop search for posts instead of pages.
本文标签: Can I use the wordpress loop in pages
版权声明:本文标题:Can I use the wordpress loop in pages? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745553745a2155750.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论