Exluding “pages” from query_posts

I have a page that lists all posts with a certain category “news”. The first result is always itself – the page! The page doesn’t even have a category but for some reason is listed as one. I only want to retrieve ‘posts’.

My query is:

Read More
query_posts( array ( 'category_name' => 'news', 'posts_per_page' => 4, 'orderby' => 'date', 'order' => 'ASC', 'post_type' => 'post' ) );

The resulting page can be seen here:

http://vl.social-gamer.com/news-blog/

I appreciate any help. I’m a bit of a WP noob still.

Thanks!

Related posts

Leave a Reply

1 comment

  1. If what you’re trying to do is just get a list of categories, then I’d suggest a function already inside of WordPress called wp_list_categories(). Here’s the documentation on that particular function.

    Displays a list of Categories as links. When a Category link is
    clicked, all the posts in that Category will display on a Category
    Page using the appropriate Category Template dictated by the Template
    Hierarchy rules.

    Keep in mind, this will also echo out the categories, not just retrieve them. I find myself using this function quite often:

    <?php wp_list_categories('title_li='); ?>
    

    However, if you’re looking to find just the “posts” of a certain category and not the “pages” as well then understand that pages in WordPress are nearly the same thing as posts in WordPress. Pages for one can’t have a category, but posts can. Posts are sorted by date, and pages are not. There’s some discrepancies, but for all intents and purposes, there’s not a huge difference in how you should code between the two. Here’s some more information on that discussion.

    EDIT

    The author of the post appears to have this problem due to an improper file structure. For references to a good fule structure please see this link.

    index.php
    header.php
    sidebar.php
    footer.php
    functions.php
    style.css
    page.php <– This isn’t in the article from the link, but it should be added to decide between a page layout of a page of posts layout.