- Tham gia
- 28/02/2015
- Bài viết
- 15,966
- Được Like
- 12,454
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
library/XenForo/ViewPublic/Forum/View.php
Admin CP -> Appearance -> Templates -> thread_list_item
Demo:
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 đó.
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:
Nguồn: tailieu24h.net