2013-07-22 26 views
-4

我試圖實現顯示多個divs中的更多鏈接(如這裏http://www.gutscheinpony.de/outletcity.html,你點擊細節,你會得到隱藏的div) 但是我通過PHP和分類達到50個領域喜歡在這些方面,我需要個人ID,這樣我可以分開打開每個DIV。問題是我需要通過php給每個div一個變量id!但我卡住了。你可以在這裏看到問題http://cloud0815.joloshop.com/shops/1822direkt(點擊兩個「顯示更多」文本),只有第一個會打開!!!)顯示更多在一個div與php和css

+0

的方式做好了充足這裏有:http://stackoverflow.com/questions/2717181/cut-text-after-x-amount-of-characters,並通過http://stackoverflow.com/search?q=truncate+string+php –

+0

謝謝,但是,那不是問題。我想在一行之後剪切文本並且有一個(鏈接)更多......並且其他行應滑動打開... – user2605258

回答

0

如果你使用jQuery,你不需要給每個div一個單獨的ID。您可以爲每個「顯示更多」鏈接提供一個類似「show-more」的鏈接。然後,將鏈接綁定到點擊處理程序。 $(this)變量告訴你50個鏈接中的哪個被點擊了。你如何選擇包含隱藏的文本的div取決於您的標記,但這裏是你可以做什麼的例子:

PHP:

/* Inside a loop */ 
<?php 
     $full_text = get_the_content(); 
     $period_pos = strpos($full_text, "."); 
     $excerpt = substr($full_text, 0, $period_pos+1); // Get the first line, assuming that a line ends with a period. 
     $rest = substr($full_text, $period_pos+1);   // Get the rest of the text 
?> 
<div class="excerpt"> 
     <?php echo $excerpt; ?> 
</div> 
<div class="rest"> 
     <?php echo $rest; ?> 
</div> 
<div class="show-more-div"> 
    <a href="#" class="show-more">Show more</a> 
</div> 

的jQuery:

$(document).ready(function(){ 
     $(".show-more").click(function(){ 
      $(this).parent().prev().slideDown();  
     }); 
}); 
+0

我也可以代替20個字符選擇第一行的內容嗎? – user2605258

+0

當然,看我的編輯。 – PhoenixWing156

+0

謝謝,最後一個。我得到的內容通過PHP顯示,我在哪裏把代碼<?php the_content(); ?> – user2605258