single.php 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!
- The topic ‘single.php outputs all posts :(’ is closed to new replies.