2014-12-11 70 views
0

問題:需要截斷帖子。如何截斷使用PHP的帖子?

當前情況:整篇文章正在顯示。 [閱讀更多...]錯誤的位置。

目標:截斷到350個字符的帖子顯示。放置「[閱讀更多...]」文字結尾。

請參閱當前的代碼:

<?php if ($posts = $this->getRecent()): 

// get The ReadMore value from configuration 
$configReadmore = Mage::getStoreConfig('blog/blog/readmore',Mage::app()->getStore()); 

?> 
<div class="widget-latest"> 
    <center><font size=6em><font color=004689><?php echo Mage::helper('blog')->__('Top Articles'); ?></font size></font color></center> 
    <ul style="list-style: none; padding-left: 0px;"> 
     <?php foreach ($posts as $post): ?> 
     <li style="border: 1px solid #9a9a9a; margin-bottom: 10px;"> 
      <div class="postTitle"> 
       <h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2> 

      </div> 

     <?php echo $post->getShortContent(); ?> 
       <br/><br/><a href="' . $post->getAddress() . '">[Read More...]</a> 


      </li> 
     <?php endforeach; ?> 
    </ul> 
    </div> 

底部網站:http://www.statis-online.com

所有幫助是非常感謝!

回答

0

使用此代碼沒有的字符的顯示:

<?php Mage::helper('core/string')->truncate($post->getShortContent(), 100); ?> 

More info to code

+0

感謝夥計!最終代碼的工作如下: <?php echo Mage :: helper('core/string') - > truncate($ post-> getShortContent(),350); ?> – Lykingond 2014-12-11 14:30:27

+0

你會碰巧知道如何製作代碼**************「[Read More...]」***************代碼顯示紅色字體沒有打破鏈接?此代碼打破了鏈接:/ – Lykingond 2014-12-11 16:23:44