Title: query_posts question
Last modified: August 18, 2016

---

# query_posts question

 *  Resolved [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/)
 * > > <?php if (have_posts()) : ?>
   > >  <?php query_posts(‘cat=3’); ?>
   > > </h1>
   > >  <h2 class=”tagline”><?php echo c2c_get_custom(‘tagline’); ?> <?php
   > > edit_post_link(‘Edit’,'(‘, ‘)’); ?> </h2>
   > >  <div class=”storycontent”>
   > >  <?php the_excerpt_reloaded(70,”,”, true, ‘<br
   > > ><div class=”moretext”>Read On …</div>’); ?> <?php wp_link_pages(); ?> </
   > > div>
   > > <?php else : ?>
   > >  <p>No post found.</p> <?php endif; ?></div>
   > Can anyone tell me why this is displaying the most recent overall post, not
   > the most recent in the category?

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/query_posts-question-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/query_posts-question-1/page/2/?output_format=md)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-635968)
 * Wouldn’t those first two lines be reversed?
 *     ```
       <?php query_posts('cat=3'); ?>
       <?php if (have_posts()) : ?>
       ```
   
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636192)
 * Yeah, thats a styled category page, not an archive.
 * eg.
    [http://iheartau.com/wordpress/albums/](http://iheartau.com/wordpress/albums/)
 * Nothing – see?
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636193)
 * Well, if you meant that you want to use a Page (as in [Pages](http://codex.wordpress.org/Pages))
   to display posts from a category… you are way off! Wrong thinking.
 * Use [Category_Templates](http://codex.wordpress.org/Category_Templates).
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636198)
 * Sorry – wrong topic! The code the other way round displays the most recent post
   overall as well …
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636200)
 * Even if it displays… you are still wrong in your approach.
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636249)
 * Care to tell me how I should be doing it?
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636251)
 * I just did it [above](http://wordpress.org/support/topic/138431?replies=7#post-631410).
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636255)
 * No, this code is for the home.php – to display the newest entry from a category.
   My reply about the “styled category page” was misplaced.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636257)
 * I guess you should have been a bit more explicite when you made your initial 
   post: nothing said that was for an index. Sorry.
 * In your index you can use one, two, 3, more… Loops or you can just have a plugin
   that exludes categories from being shown on the main page.
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636457)
 * But shouldn’t that code work, hypothetically? Take a look at [http://iheartau.com/wordpress](http://iheartau.com/wordpress)
   and scroll past the ad, you’ll see what I’m trying to do.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636459)
 * My issue with this kind of questions is… I have no idea what you are trying to
   do. When users _think_ they know how to go about a problem/question and they 
   go technical and post code – I am lost, sorry.
 * I prefer a detailed laymen description of what the end goal is, then we might
   be able to tell the “how-to” (if there is a solution).
 * If your main page is displayed by a home.php file as you stated above, I might
   assist you since I also have a blog where I have a home.php with 4 different 
   Loops and I know exactly how that template file works. But if you give just one
   bit of info in every 24 hours about what you want… that will not work. Like it
   was with your initial post: why it doesn’t work? How the heck should we know 
   where you are using it and why???
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636461)
 * Alright then.
 * It’s an excerpt from a piece of code on my home.php, where I want to pull the
   last entry from a specific category to be displayed. You’ll see on iheartau.com/
   wordpress – after the advertisement – that it’s already displaying, but it’s 
   displaying the latest entry overall, not from the category specified.
 * The code running in that particular div is:
 * <?php if (have_posts()) : ?>
    <?php query_posts(‘cat=3’); ?>
 * <h1 class=”subtitle_home”><?php the_title(); ?></h1>
    <h2 class=”tagline”><?php
   echo c2c_get_custom(‘tagline’); ?> <?php edit_post_link(‘Edit’,'(‘, ‘)’); ?> 
   </h2>
 * <div class=”storycontent”>
    <?php the_excerpt_reloaded(70,”,”, true, ‘<br><div
   class=”moretext”>Read On …</div>’); ?> <?php wp_link_pages(); ?> </div>
 * <?php else : ?>
    <p>No post found.</p> <?php endif; ?>
 * Any help provided would be extraordinary.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636462)
 * Sory, but MichaelH told you several posts and days ago… the first two lines are
   in wrong oder!
    The query_post should come BEFORE the Loop starts, and I don’t
   see the loop finished.
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636463)
 * I have this in one of my blogs:
 *     ```
       <?php query_posts('cat=-3&showposts=4'); // exclude the third category ?>
   
        <?php while (have_posts()) : the_post(); // start your Loop ?>
   
       <h4 class="storytitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
       <?php the_time('d.m.Y'); ?><br />
       <?php the_excerpt_reloaded(30, '', '<a><img>', TRUE, 'Keep reading...', FALSE, 2); ?>
   
        <?php endwhile; ?>
       ```
   
 * It does the opposite: excludes one category (the minus sign) and shows 4 posts,
   but you should get the idea.
 *  Thread Starter [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * (@goodonpaper)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/#post-636464)
 * Perfection – thank you!

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/query_posts-question-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/query_posts-question-1/page/2/?output_format=md)

The topic ‘query_posts question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 17 replies
 * 3 participants
 * Last reply from: [goodonpaper](https://wordpress.org/support/users/goodonpaper/)
 * Last activity: [18 years, 6 months ago](https://wordpress.org/support/topic/query_posts-question-1/page/2/#post-636481)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
