[wp-trac] Re: [WordPress Trac] #6484: have_posts does not seem to
work outside of the loop
WordPress Trac
wp-trac at lists.automattic.com
Mon Mar 31 22:10:51 GMT 2008
#6484: have_posts does not seem to work outside of the loop
---------------------+------------------------------------------------------
Reporter: jsherk | Owner: anonymous
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: General | Version: 2.5
Severity: normal | Resolution:
Keywords: |
---------------------+------------------------------------------------------
Changes (by jsherk):
* status: closed => reopened
* resolution: invalid =>
Comment:
Okay, I gave a bad example... I was trying to say that there MUST be
posts, because when I put a valid ID in, it returns the title, yet
have_posts returns empty, when it should in fact return as true or 1. I
tried both your examples above...
Example #1 returns a blank browser screen (in both IE6 and FF2).
Example #2 returns bool(false) (in both IE6 and FF2).
HOW TO RECREATE PROBLEM
I copied the code right out of 'the loop' and have_posts still comes up
empty. The blog itself works fine... have_posts returns what it should
when it is used in the loop. BUT if I copy the same code into a seperate
file, and use require('wp-blog-header') then have_posts returns nothing.
The problem only occurs when have_posts is in a seperate file (not in the
loop).
Sample Code: (needs to be in it's own file like test.php or whatever)
{{{
<?php require('wp-blog-header.php'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent
Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?>
--></small>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', ''); ?> Posted in
<?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »');
?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries')
?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »')
?></div>
</div>
<?php else : ?>
<h2 class="center">Nothing Found</h2>
<?php endif; ?>
}}}
Here is the link to the forum where somebody else is having the same
problem...
http://wordpress.org/support/topic/164871
---
--
Ticket URL: <http://trac.wordpress.org/ticket/6484#comment:5>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list