0
我有這個代碼爲幻燈片創建導航。它工作得很好,但其中一個變量是將代碼呈現在錯誤的位置。正如你可以看到$imgCount
(3的3)應該在<div class="next-prev"> </div>
之內,但是它在這個div之前就已經出現了。PHP在錯誤的地點輸出代碼
爲什麼它在div編碼裏面移動?
以下是我期待它輸出:
<div class="slideshow-nav">
<div>
<div class="next-prev">
<a href="/slideshow-one/2/">← Previous 3 of 3 </a><a href="../">Back to Slide One</a>
</div>
</div>
</div>
這裏的它是如何輸出:
<div class="slideshow-nav">
<div>3 of 3
<div class="next-prev">
<a href="/slideshow-one/2/">← Previous </a><a href="../">Back to Slide One</a>
</div>
</div>
</div>
下面是設置它的代碼:
<div class="slideshow-nav">
<div class="img-count">
<?php function img_count() {
global $page, $numpages;
echo "$page of $numpages";
} ?>
</div>
<div>
<?php
global $page, $numpages;
$imgCount = img_count();
if ($page < 2)
$next = '<span class="start-ss">Go</span>';
else
$next = ' Next →';
if ($page == $numpages)
$previous = '← Previous ' .$imgCount. ' <a href="../">Back to Slide One</a>';
else
$previous = '← Previous ...';
wp_link_pages(
array(
'before' => '<div class="next-prev">',
'after' => '</div>',
'next_or_number' => 'next',
'nextpagelink' => $next,
'previouspagelink' => $previous,
));
?>
</div>
</div>
完美,謝謝!只是好奇,爲什麼這很重要? – mattz 2010-12-12 08:46:29
'echo'會立即輸出字符串(這就是爲什麼它會在您調用函數的同一位置顯示在輸出中),*不能*被分配給字符串(不使用輸出緩衝,但不需要那現在)。 'return'將該字符串設置爲可以*分配給變量的函數的返回值。 – 2010-12-12 11:03:03
感謝您的回答! – 2014-10-21 15:58:55