Other Xem trước bài viết ở Thread List trong XenForo

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
16,829
Được Like
12,687
Xem trước bài viết ở Thread List trong XenForo

Thông thường, xenforo chỉ hiển thị tooltip khi bạn muốn xem trước nội dung của bài viết nào đó ở thread list (trang danh sách các bài viết). Như vậy cũng khá là bất tiện. Nên bài viết này sẽ hướng dẫn các bạn cách thêm một đoạn mô tả để người dùng có thể xem trước 1 phần bài viết ngoài thread_list.

Bước đầu tiên chúng ta vào host, sửa file View.php ở đường dẫn /library/XenForo/ViewPublic/Forum. Tìm đoạn (mở = notepad có thể nằm ở dòng 15 nhé)
Mã:
  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
     );
   }

Sửa lại thành:
Mã:
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']);
            }
        }
    }

Tiếp tục tìm file Forum.php ở đường dẫn /library/XenForo/ControllerPublic. Sau đó tìm đoạn code (dự kiến ở dòng 363):
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,
            '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
        );
    }

Thay bằng:
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
        );
    }

Sau đó vào ACP-->Styles-->Templates--> Tìm template thread_list_item. Tìm:
Mã:
<div class="secondRow">
  <div class="text">
  <blockquote>{xen:string nl2br, {xen:helper wordtrim, $thread.messageParsed, $xenOptions.discussionPreviewLength}}</blockquote>
  </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>

Thay bằng:
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>
  <p><p><span class="tukhoa">Từ khóa: </span><span class="backgroundtags">{xen:helper Tinhte_XenTag_getImplodedTagsFromThread, $thread, 1}</span>
  </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>

Sau đó thêm đoạn code sau vào template Extra.css để làm đẹp cho Tags:
Mã:
/* Từ khóa */
.tukhoa {
    background-color: @primaryDarker;
    padding-left: 15px !important;
    padding-right: 5px !important;
    margin: 0px !important;
    color: @contentBackground;
    display: inline-block;
    font-weight: normal;
    border-radius: 0px;
    text-transform: uppercase;
}
.backgroundtags {
  color: #ffffff !important;
  padding-left: 15px !important;
  padding-right: 5px !important;
  text-transform: uppercase;
  margin: 0px !important;
}

Có thể chỉnh sửa theo ý thích của bạn. Cuối cùng là lưu lại và tận hưởng nhé.

Chúc các bạn thành công.


Nguồn: xfteam.net​
 

Richard Ngo

Private
Tham gia
12/08/2015
Bài viết
3
Được Like
2
Anh @VPS ơi, cho em hỏi trên FX2 thì mình làm sao để hiển thị được phần trích dẫn này hả anh?
Em mò mãi mà không được.
Em cảm ơn anh nhiều ạ!
 

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

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mobile/Zalo: 0906081284

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