Ready to get started?Download WordPress


[resolved] Pretty Permalinks make have_posts() return false (2 posts)

  1. maxkool
    Posted 5 years ago #

    I'm using WordPress as a CMS and have the following setup:
    - home.php in root
    - WordPress installed in ./wordpress/

    Home.php contains:

    define('WP_USE_THEMES', false);
    <...HTML CONTENT...>
    <?php if (have_posts()) : ?>
    <?php query_posts('showposts=1'); ?> //I only want to show the latest post on my homepage
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_content('Read the rest &raquo;'); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Everything works fine with Permalinks set to standard.
    However when using any other setting for Permalinks (I want to use /%category%/%postname%/) the post doesn't show. It turns out this is because have_posts() returns false. If I remove <?php if have_posts()) : ?> altogether, then the post does show - entirely. That is to say, the_content() does not work in this case, since the article has a MORE tag at some point.

    In case you're wondering, mod_rewrite is enabled. Also, when I access the blog itself (./wordpress/index.php) everything works just fine.

    So, does anyone have any idea why have_posts() should return false when using any other permalinks other than the standard ones?

  2. maxkool
    Posted 5 years ago #

    I've finally managed to work it out.

    It seems that (almost) all of the trouble I was having was because I forgot to change the blog URI to the root of my website.

    However, after doing this, though the post on the homepage was displayed correctly, the links were incorrect. (of the type ./category/postname, as if I had installed WP in the root dir) But this was easily fixed by changing the permalink URI to /wordpress/%category%/%postname%/)

Topic Closed

This topic has been closed to new replies.

About this Topic