[resolved] Problem with "php query_posts" please help.. (6 posts)

  1. altacivil
    Posted 9 years ago #

    I have my WP set up so that it does not show certain posts (namely those within category 7). I am using
    "<?php query_posts('cat=-7'); ?>" as perscribed within the codex. This technique works excellent, there is just one small problem. When I input this into my template before "the loop" (even if I put it immediately below the code that obtains the headder) my "previous" and "next posts" links fail to work properly.

    By fail to work properly I mean they show up like they are supposed to, but the posts are the same on the page. I click on "previous posts" link and the page changes (the URL changes), but the same posts as are on the main page show up. When I remove the "<?php query_posts('cat=-7'); ?>" code from my template, the previous and next posts links beging to work properly.

    Anyone know how I can use the query_posts code and get the previous and next posts links to work properly?

    Here is my page... http://gpetzold.swifthost.net (as it sits now, the code is in the template so you can see how it is not working properly...


  2. Joshua Sigar
    Posted 9 years ago #

    <?php query_posts('cat=-7'); ?>
    Change that one line code to the following.

    <?php $wp_query->set( 'cat', '-7' ); ?>
    <?php query_posts( '' ); ?>

  3. altacivil
    Posted 9 years ago #

    A big thanks to alpaoide!

    That worked great for the case where i have it set to "set('cat', '-7')" but when I want to display ONLY the posts in category 7 (on a different page in my site) ie. "set('cat', '7')" i get an error 404 page when I try to view the "previous posts" page.

    Any ideas?

  4. dumpling
    Posted 9 years ago #

    Did you ever find a fix for this problem? I have the same.

  5. dbasulto
    Posted 9 years ago #

    i have the same issue, with 1.5.2. I'm going to upgrade to 2.0 soon, i wonder if the problem still exists in 2.0, or if there's another way to do it in 2.0

  6. Seaborn
    Posted 8 years ago #

    Im on the latest version and I also have the same problem.
    This is what I am using

    <?php query_posts('cat=-0'); //gets all posts
    load_template( TEMPLATEPATH . '/index.php'); //loads index

    any thoughts?


Topic Closed

This topic has been closed to new replies.

About this Topic