WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] loop doesn't work on homepage with pretty urls (6 posts)

  1. juaron
    Member
    Posted 5 years ago #

    on my site I have wordpress (2.7) installed in a directory called blog. on the homepage of my domain (which does not use wordpress), I want to show the latest posts. To do so, I use this code below. All works fine, but now I want to use pretty urls for my permalinks. When I adjust the urls, I get the message "not found" on the homepage (the pages in the blog directory still work fine). Can anyone help me out please?

    <?php
    require('blog/wp-blog-header.php');
    if (have_posts()) :
    	while (have_posts()) : the_post();
    		//all code for the loop here
    	endwhile;
    else : ?>
    	<h2 class="center">Not found</h2>
    	<?php
    	get_search_form();
    endif;
    ?>
  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    You don't have a defined query, so you don't get any posts. Normally, when using a theme, you get the default query. Since you're outside of WordPress and themes, you don't.

    So, add a query_posts(); call before your Loop, to make it actually perform the default posts query.

  3. juaron
    Member
    Posted 5 years ago #

    Thanks for your quick answer! that is a step in the right direction. However, when I just add "query_posts()" I get a missing argument error. When I look at the function reference, it seems I need to specify a query string. What should I use there to get the same result I normally get from the blog indexpage?
    and secondly: you state I don't get a default query since I'm outside of wordpress. But all goes well when I don't use pretty url's. Can you explain how that makes a difference?

  4. juaron
    Member
    Posted 5 years ago #

    I'm now using query_posts(""); and that seems to work fine. Still don't understand why pretty urls make a difference though...

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    you state I don't get a default query since I'm outside of wordpress. But all goes well when I don't use pretty url's. Can you explain how that makes a difference?

    Sure. Default URLs pass parameters through GET parameters. "Pretty" URLs pass them as part of the URL itself.

    When you're using pretty permalinks, and also using a URL that is not within the WordPress pattern that it's expecting, then it gets the URL and can't figure it out. So it doesn't know what posts are being asked for.

    With the normal default URLs, this doesn't happen, since it's only looking at the GET parameters, and not the URL itself.

  6. juaron
    Member
    Posted 5 years ago #

    ok that's clear - thanks a lot. Am I right in using an empty string as query parameter for getting the "usual" query?

Topic Closed

This topic has been closed to new replies.

About this Topic