wordpress if(have_posts()),循环不起作用
just wondering can anyone see anything wrong with this code. It worked perfectly on the development version, and this is an exact copy.
I thought it may have been something within the loop but I even tried echo 'hello';
straight after the if ( have_posts () ) :
and nothing appeared, yet I did the same immediately before the if
and it appeared.
Here is the overall code....
if ( have_posts() ) :
$the_query = new WP_Query( array ( 'posts_per_page' => 1, 'p' => 4998 ) ); /* */
while ($the_query->have_posts() ) : $the_query->the_post();
the_content();
endwhile;
wp_reset_postdata();
endif;
?>
Thanks for any help.
EDIT : Apologies if my problem sounded vague, basically whats not working is that nothing at all is appearing even though the post ID is correct and there is no other issues regarding css etc as to why it wouldnt appear. And even after trying to just display a word like "hello" after the if
, still nothing.
Im just confused as to why this would stop working all of a sudden.
Thanks again.
只是想知道任何人都可以看到这段代码有什么问题。 它完全适用于开发版本,这是一个精确的副本。 p>
我认为它可能是循环内的东西,但我甚至尝试过 以下是整体代码.... p>
感谢您提供任何帮助。 p>
编辑:如果我的问题听起来含糊不清,我会道歉,基本上没有工作的是什么都没有 一切都出现了,即使帖子ID是正确的,并且没有关于css等的其他问题,为什么它不会出现。 甚至在尝试在 echo'hello'; 代码>直接在
if(have_posts()): code>之后没有出现,但我在
if code>之前做了同样的事情并且它出现了。 p>
\ n
if(have_posts()):
$ the_query = new WP_Query(array('posts_per_page'=> 1,'p'=> 4998)); / * * /
while($ the_query-> have_posts()):$ the_query-> the_post();
the_content();
endwhile;
wp_reset_postdata();
endif;
?>
code> pre>
if code>之后只显示“hello”之类的单词之后,仍然没有。
我只是为什么会突然停止工作而感到困惑。
再次感谢。 p >
div>
Yep I checked. Use have_posts() on the query you create (create query outside if
)
http://codex.wordpress.org/Class_Reference/WP_Query
As a global call, have_posts() checks if the page, if configured the right way, has posts.