title: PHP Outputting Code in the Wrong Spot
body: <p>I have this code that creates the navigation for a slideshow.  It works just fine except that one of the variables is rendering the code in the wrong place.  As you can see below <code>$imgCount</code> (3 of 3) should be inside <code>&lt;div class="next-prev"&gt;  &lt;/div&gt;</code> however it's showing up before this div.</p>
  
  <p>Why is it moving itself outside the div that it's coded inside?</p>
  
  <p>Here's how I expect it to output:</p>
  
  <pre><code>&lt;div class="slideshow-nav"&gt;
      &lt;div&gt;
           &lt;div class="next-prev"&gt;
               &lt;a href="/slideshow-one/2/"&gt;&amp;larr; Previous  3 of 3  &lt;/a&gt;&lt;a href="../"&gt;Back to Slide One&lt;/a&gt;
           &lt;/div&gt;  
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here's how it is outputting:</p>
  
  <pre><code>&lt;div class="slideshow-nav"&gt;
      &lt;div&gt;3 of 3
           &lt;div class="next-prev"&gt;
               &lt;a href="/slideshow-one/2/"&gt;&amp;larr; Previous  &lt;/a&gt;&lt;a href="../"&gt;Back to Slide One&lt;/a&gt;
           &lt;/div&gt;  
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here's the code that sets it up:</p>
  
  <pre><code>&lt;div class="slideshow-nav"&gt;
      &lt;div class="img-count"&gt;
          &lt;?php function img_count() {
              global $page, $numpages;
              echo "$page of $numpages"; 
              } ?&gt;
        &lt;/div&gt;
       &lt;div&gt;
          &lt;?php 
              global $page, $numpages;
                      $imgCount = img_count();
                  if ($page &lt; 2)
                      $next = '&lt;span class="start-ss"&gt;Go&lt;/span&gt;';
                  else
                      $next = ' Next &amp;rarr;';
                  if ($page == $numpages)
                      $previous = '&amp;larr; Previous  ' .$imgCount. ' &lt;a href="../"&gt;Back to Slide One&lt;/a&gt;';
                  else
                      $previous = '&amp;larr; Previous  ...';
              wp_link_pages(      
                  array(
                  'before' =&gt; '&lt;div class="next-prev"&gt;',
                  'after' =&gt; '&lt;/div&gt;',
                  'next_or_number' =&gt; 'next',
                  'nextpagelink' =&gt; $next,
                  'previouspagelink' =&gt; $previous,
                  )); 
              ?&gt;  
         &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>