admin管理员组文章数量:1394181
I know this is a really newbie question, but I can't seem to get the loop to pull from the posts. all it is doing is pulling from the page itself.
I made a template and added the loop to it.
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
edit: here is all the code:
I know this is a really newbie question, but I can't seem to get the loop to pull from the posts. all it is doing is pulling from the page itself.
I made a template and added the loop to it.
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
edit: here is all the code: http://pastebin/k2rDu53b
Share Improve this question edited Dec 22, 2011 at 20:20 user766607 asked Dec 22, 2011 at 20:13 user766607user766607 951 gold badge1 silver badge5 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 23Because you're on a page, that's only going to display the query for that page. As such, you'd have to create a new query to bring in the posts you want. Replace your loop with this:
<?php
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
Here some more information on the query: http://codex.wordpress/Class_Reference/WP_Query
本文标签: simply loop through posts
版权声明:本文标题:simply loop through posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744723955a2621861.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_header()
instead, if it needs to differ from the main header file, create another eg.header-two.php
with the code and call that in the template instead, eg.get_header( 'two' )
– t31os Commented Dec 23, 2011 at 12:25