Title: loop help please!
Last modified: August 19, 2016

---

# loop help please!

 *  [vschimel2](https://wordpress.org/support/users/vschimel2/)
 * (@vschimel2)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/loop-help-please/)
 * hi, i’m desperate for some help. i’m trying to get my homepage to only display
   posts & images tagged one specific category. this is the index.php file, part
   i added in to restrict to one category (40) is bolded. but it doesn’t seem to
   be working (all new posts are appearing on the homepage). what am i missing? 
   any help would be SO appreciated – thanks!
 * <?php get_header(); ?>
    <!– Content Wrap –> <div id=”galleryWrap”> <!– Gallery–
   > <div id=”gallery”> **<?php $posts = get_posts(“category=40&numberposts=6”);?
   >** <?php if(have_posts()) : ?><?php while (have_posts()) : the_post(); ?> <!–
   Thumbs –> <div id=”site-<?php the_ID(); ?>” class=”thumbs”> ID, “Url”, true);?
   >” title=”<?php the_title();?>”><img src=”<?php echo get_post_meta($post->ID,“
   small”, true); ?>” alt=”<?php the_title();?>” class=”thumbnail” /> </div><!– [
   END] thumbs –> <?php endwhile;?> <?php if(function_exists(‘wp_pagenavi’)) { wp_pagenavi();}?
   > <?php endif; ?> </div><!– [END] gallery –> <?php get_sidebar();?> </div><!–[
   END] galleryWrap –> <?php get_footer(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/loop-help-please/#post-1059169)
 * If this is your index.php then change that line to this:
 * <?php query_posts($query_string . ‘&cat=40’); ?>
 *  Thread Starter [vschimel2](https://wordpress.org/support/users/vschimel2/)
 * (@vschimel2)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/loop-help-please/#post-1059304)
 * thanks SO much! one more quick question. i want to do a similar thing on a blog
   page – is this the coding i’d use?
 * <php
    /* Template Name: Page 2 */ ?>
 * <?php get_header(); ?>
 * <!– Content Wrap –>
    <div id=”galleryWrap”> <!– Gallery –> <div id=”gallery”>
 *  <?php if (is_page ()){ ?>
 *  <? } ?>
 *  <div class=”content”>
 *  ** <?php $posts = get_posts(“category=33&numberposts=10”); ?>
 *  <?php if(have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
 *  <div class=”entry”>
    <?php the_content(”); ?> </div>
 *  <?php endwhile;?>
    <?php endif; ?>
 *  </div>
    </div><!– [END] gallery content –> <?php get_sidebar();?>
 * </div><!– [END] galleryWrap
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/loop-help-please/#post-1059316)
 * Probably better to use the foreach/setup_postdata construct rather than the `
   if(have_posts()) : ?><?php while (have_posts()) : the_post(); ..... endwhile`
   thing.
 * See this example:
    [http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/](http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘loop help please!’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [17 years, 1 month ago](https://wordpress.org/support/topic/loop-help-please/#post-1059316)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
