Support » Fixing WordPress » query_posts not working

  • Resolved soggybag


    I installed a new copy of WP and set it up with a static home page. As per the instructions on the WP site using the Settings. From what I understand I should be using a page for the static home page and index.php for the news page which should be showing my blog posts. I added the following to the index.php

    <?php query_posts('category_name=news'); ?>
    	<?php if (have_posts()) : ?>

    I want to show only posts with the category news. Navigating to my News page, which from what I understand should be index.php, I still get a full list of all posts from all categories.

    What am I missing?

Viewing 4 replies - 1 through 4 (of 4 total)
  • After some experimentation I find that when I view News, which is set as the “Posts” page in Settings>Reading, WP is not loading index.php. I can’t quite figure which page it is loading.

    Problem solved! Looks like WP was showing home.php rather than index.php.

    Maybe index.php isn’t rendering the page as you’re expecting.

    Place some random text into the file..


    my random text <?php if (have_posts()) : ?>

    (save, load the page, etc)..if you don’t see the text, then it’s a good indication another one of theme’s template files is rendering the post list (and not index.php as you’re expecting).

    At least it will narrow down the issue if anything.. 🙂

    I suppose since I redirected my home page to a page. The home.php was now used as the default home for the post. Removing home.php would hae WP end up using index.php instead.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘query_posts not working’ is closed to new replies.