WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP in protected directory, .htaccessa and failing permalinks (5 posts)

  1. richarduk
    Member
    Posted 6 years ago #

    Okay, I've set up a password protected directory within my main site, and within that directory I've got WP in development for a client.

    The client can therefore access WP with the password and see what's going on.

    I think the password protection has wiped the .htaccess. Every child category I go to shows exactly the same posts, even though the permalinks in the address bar change.

    Within WP, I can change the permalink 'styles' around (e.g. default, custom etc.) and WP accepts this quite happily, so it can't be having any trouble in overwriting the .htaccess.

    The pastebin is here: http://wordpress.pastebin.ca/931080

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

    This is your problem.
    <?php query_posts('showposts=2'); ?>

    Using a query_posts changes the query to the parameters you give it. Only the parameters you give it. Since you didn't specify to keep the existing parameters, you didn't get to keep them. So going to, say, a category page doesn't work because you are wiping out the category part of the main posts query right here.

    This is explained in the documentation in somewhat more detail, but the upshot is that in your case, you really wanted this line instead:
    <?php query_posts($query_string . 'showposts=2'); ?>

  3. richarduk
    Member
    Posted 6 years ago #

    Brilliant!

    It's nearly there - if I remove <?php query_posts('showposts=2'); ?> then everything works fine, and I see all the posts, but if I use <?php query_posts($query_string . 'showposts=2'); ?> I get the 'Sorry, no posts to show' message.

    So I'm nearly there.

    I've come across this $query_string . before but never understood it - I'll put more effort in this time.

    But thanks for getting me this far, I would never have guessed this!

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

    Ahh, my bad. Typo.

    That should have been:
    <?php query_posts($query_string . '&showposts=2'); ?>

    The ampersand is important.

    The $query_string is basically the automatically generated query parameters for query_posts. When you want to add to it instead of replace it, then you can add to it by adding more parameters onto the end of it.

  5. richarduk
    Member
    Posted 6 years ago #

    Spot on!

    I shall go and change my theme around.

    Thankyou!

Topic Closed

This topic has been closed to new replies.

About this Topic