• Resolved juaron

    (@juaron)


    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;
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    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.

    Thread Starter juaron

    (@juaron)

    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?

    Thread Starter juaron

    (@juaron)

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

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    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.

    Thread Starter juaron

    (@juaron)

    ok that’s clear – thanks a lot. Am I right in using an empty string as query parameter for getting the “usual” query?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘loop doesn’t work on homepage with pretty urls’ is closed to new replies.