php
  • html
  • wordpress
  • 2012-10-15 54 views 0 likes 
    0

    好吧,我目前有這個代碼。wp微調功能

    <?php 
    
    query_posts('category_name=widgets2'); 
    
    echo "<div id='widgets-wrapper2'><div id='marginwidgets' style='overflow: auto; max- width: 100%; height: 450px; max-height: 100%; margin: 0 auto;'>"; 
    while (have_posts()) : the_post(); 
    echo "<div class='thewidgets2'>"; 
    
    echo wp_trim_words(the_content(), $num_words = 0, $more = "..."); 
    
    echo '<div style="height: 20px;"></div><a class="button2"  href="'.get_permalink().'">Read More</a></div>'; 
    endwhile; 
    echo "</div></div>"; 
    
    ?> 
    

    ,你可以看到,它就會從所有類別名稱widgets2後,然後它應該顯示它。

    這行

    echo wp_trim_words(the_content(), $num_words = 100, $more = "..."); 
    

    應修剪掉the_content()的話100,並在年底字符添加一個摘錄,但遺憾的是它不工作,相反,它只是顯示這個解除剪裁在所有的全部內容。

    希望這裏的人可以想通。我在任何建議,建議和所有相關的想法打開,謝謝。

    回答

    1

    因爲WordPress的功能the_content()回聲的內容。改爲使用功能get_the_content()

    +0

    謝謝你..很多海洛斯 –

    0

    免責聲明 - 我沒有在所有與WordPress多少經驗(不過我看你使用PHP)

    PHP原生解決方案還可以幫助你在這裏。該substr()函數返回一個字符串的一部分 -

    echo substr($longContent, 0, $numOfChars) . '...'; 
    

    參考 -

    相關問題