Thêm text preview cho bài đăng trong Thread List

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
16,830
Được Like
12,707
Cách này sẽ giúp các bạn dễ dàng cho hiển thị 1 phần nội dung của bài viết ra ngoài , thích hợp với các trang tin tức, thủ thuật.

Compatible XF Versions: Xenforo 1.2

library/XenForo/ControllerPublic/Forum.php
Mã:
protected function _getThreadFetchElements(array $forum, array $displayConditions)
    {
        $threadModel = $this->_getThreadModel();
        $visitor = XenForo_Visitor::getInstance();

        $threadFetchConditions = $displayConditions + $threadModel->getPermissionBasedThreadFetchConditions($forum);

        if ($this->_routeMatch->getResponseType() != 'rss')
        {
            $threadFetchConditions += array('sticky' => 0);
        }

        $threadFetchOptions = array(
            'join' => XenForo_Model_Thread::FETCH_USER | XenForo_Model_Thread::FETCH_FIRSTPOST,
            'readUserId' => $visitor['user_id'],
            'watchUserId' => $visitor['user_id'],
            'postCountUserId' => $visitor['user_id'],
        );
        if (!empty($threadFetchConditions['deleted']))
        {
            $threadFetchOptions['join'] |= XenForo_Model_Thread::FETCH_DELETION_LOG;
        }

        if ($this->getResponseType() == 'rss')
        {
            $threadFetchOptions['join'] |= XenForo_Model_Thread::FETCH_FIRSTPOST;
        }

        return array(
            'conditions' => $threadFetchConditions,
            'options' => $threadFetchOptions
        );
    }

library/XenForo/ViewPublic/Forum/View.php
Mã:
     * Help render the HTML output.
     *
     * @return mixed
     */
    public function renderHtml()
    {
        $this->_params['renderedNodes'] = XenForo_ViewPublic_Helper_Node::renderNodeTreeFromDisplayArray(
            $this, $this->_params['nodeList'], 2 // start at level 2, which means only 1 level of recursion
        );


        // RENDER FIRST POSTS
        $previewLength = XenForo_Application::get('options')->discussionPreviewLength;

        foreach ($this->_params['threads'] AS &$thread)
        {
            if ($previewLength && !empty($thread['message']))
            {
                $formatter = XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_Text');
                $parser = XenForo_BbCode_Parser::create($formatter);

                $thread['messageParsed'] = $parser->render($thread['message']);
            }
        }
    }

Admin CP -> Appearance -> Templates -> thread_list_item
Mã:
<div class="secondRow">
                <div class="text">
                    <blockquote>{xen:string nl2br, {xen:helper wordtrim, $thread.messageParsed, $xenOptions.discussionPreviewLength}}</blockquote>
                </div>
   
                <div class="posterDate muted">
                    <xen:username user="$thread" title="{xen:phrase thread_starter}" /><span class="startDate">,
                    <a{xen:if {$visitor.user_id}, ' href="{xen:link threads, $thread}"'} class="faint"><xen:datetime time="$thread.post_date" title="{xen:if {$visitor.user_id}, '{xen:phrase go_to_first_message_in_thread}'}" /></a></span><xen:if is="{$showForumLink}"><span class="containerName">,
                    <a href="{xen:link forums, $thread.forum}" class="forumLink">{$thread.forum.title}</a></span></xen:if>

                    <xen:if is="{$showLastPageNumbers} AND {$thread.lastPageNumbers}">
                        <span class="itemPageNav">
                            <span>...</span>
                            <xen:foreach loop="$thread.lastPageNumbers" value="$pageNumber">
                                <a href="{xen:link threads, $thread, 'page={$pageNumber}'}">{$pageNumber}</a>
                            </xen:foreach>
                        </span>
                    </xen:if>
                </div>

                <div class="controls faint">
                    <xen:if is="{$thread.canEditThread}"><a href="javascript:" data-href="{xen:link 'threads/list-item-edit', $thread}" class="EditControl JsOnly">{xen:phrase edit}</a></xen:if>
                    <xen:if is="{$showSubscribeOptions} AND {$thread.email_subscribe}">{xen:phrase email}</xen:if>
                </div>
            </div>

Demo:

untitled.PNG

P/s: Các bạn tìm và thay thế code cũ bằng các code trên nha. BBcode vẫn còn hiện nha! Như hình demo vậy đó.

Nguồn: tailieu24h.net​
 

agrione

Corporal
Tham gia
07/09/2015
Bài viết
119
Được Like
97
Làm sao để ko hiện bbcode được chủ thớt
 

onlyonelove

MasterCorporal
Tham gia
03/11/2015
Bài viết
367
Được Like
213
có ai rành hướng dẫn mình phát triển tính năng này thành addon ddc k?
 

Hướng dẫn sử dụng

Dịch vụ XenForo của VNXF

Telegram: anhanhxf

Chỉ nhận web nội dung lành mạnh

Nhà Tài Trợ

Mút Xốp Không Gian
Mút Sofa Không Gian
Top Bottom