如何使用PHP截断帖子?

问题描述 投票:0回答:1

问题:需要截断帖子。

当前情况:整个帖子正在显示。 [阅读更多...]处于错误的位置。

目标:截断显示的帖子的350个字符。将“[Read More ...]”放在文本末尾的位置。

请查看当前代码:

<?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><><?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 ; 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>

网站底部:

magento blogs truncate
1个回答
0
投票

使用此代码不显示字符:

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

More info to code

© www.soinside.com 2019 - 2024. All rights reserved.