Title: single.php outputs all posts :(
Last modified: August 19, 2016

---

# single.php outputs all posts :(

 *  [devotee](https://wordpress.org/support/users/devotee/)
 * (@devotee)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/)
 * Hey. I´m pretty noobish on wordpress so bare with me.
 * I´m building a portfolio which uses two loops, one in the header to output two
   posts with information about me, and my contact information. And one other loop
   to output the content in the form of thumbnail links.
 * My problem arose when I added the second loop. Now my single.php outputs all 
   the contents, not just the one connected to the thumbnail the user clicks on.
 * The relevant code looks like this:
 * Header.php:
    <?php query_posts(‘cat=3’); ?> <?php while (have_posts()) : the_post();?
   > <p class=”abouttitle”><?php the_title(); ?></p> <div id=”abouttext”><?php the_content();?
   ></div> <?php endwhile; ?>
 * Index.php:
    <?php query_posts(‘cat=1’); ?> <?php while (have_posts()) : the_post();?
   > <div class=”post shadow grid_4″> <div class=”thumbnail”>“><?php the_post_thumbnail(‘
   portfolio’); ?></div> <h2 class=”title”><?php the_title(); ?></h2> </div> <?php
   endwhile; ?>
 * Single.php:
    <?php query_posts(“cat=-3”);?> <?php while (have_posts()) : the_post();?
   > <div id=”single-text” class=”grid_4″> <!– text –> <h2 class=”post_title”><?
   php the_title();?></h2> <?php ob_start(); the_content(‘Read the full post’,true);
   $postOutput = preg_replace(‘/<img[^>]+./’,”, ob_get_contents()); ob_end_clean();
   echo $postOutput; ?> </div>
 *  <div id=”single-picturearea” class=”grid_12″> <!– picture –>
    <?php $beforeEachImage
   = “<div class=’single-picture’>”; $afterEachImage = “</div>”; preg_match_all(“/(
   <img [^>]*>)/”,get_the_content(),$matches,PREG_PATTERN_ORDER); for( $i=0; isset(
   $matches[1]) && $i < count($matches[1]); $i++ ) { echo $beforeEachImage . $matches[
   1][$i] . $afterEachImage; } ?> </div> </div> <?php endwhile; ?>
 * Any help would be much appreciated!

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

 *  [allnut](https://wordpress.org/support/users/allnut/)
 * (@allnut)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/#post-1908909)
 * link to site would be good please.
 * 4th line of your loop in index.php file is invalid. Not sure if this would fix
   the problem?
 *  Thread Starter [devotee](https://wordpress.org/support/users/devotee/)
 * (@devotee)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/#post-1908911)
 * [http://www.johandahl.com](http://www.johandahl.com)
 * Actually, I think I got it now.
    I changed my single.php to use get_post instead,
   and the header uses this code instead:
 * <?php $post_id = 85; $queried_post = get_post($post_id); ?>
    <p class=”abouttitle”
   ><?php echo $queried_post->post_title; ?></p> <div id=”abouttext”><p><?php echo
   $queried_post->post_content; ?></p>
 * There seems to be so many ways to output content with wordpress, I get confused
   🙁 I dont really know when to use what, and when I change things and they suddenly
   work…i dont really know what I did right ^^
 *  Thread Starter [devotee](https://wordpress.org/support/users/devotee/)
 * (@devotee)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/#post-1908912)
 * Hey, thanks for noticing that 4:th line. I dont think it made any differense 
   because it was still there when I got it to work, but I cleaned it up anyway.
 *  [allnut](https://wordpress.org/support/users/allnut/)
 * (@allnut)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/#post-1908913)
 * no probs, glad you’ve sorted it.
 *  Thread Starter [devotee](https://wordpress.org/support/users/devotee/)
 * (@devotee)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/#post-1908914)
 * Actually I just noticed when I cleaned it up that my thumbnails where not displayed,
   so it must have been right from the beginning! Confusing lol!

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

The topic ‘single.php outputs all posts :(’ is closed to new replies.

 * 5 replies
 * 2 participants
 * Last reply from: [devotee](https://wordpress.org/support/users/devotee/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/singlephp-outputs-all-posts/#post-1908914)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
