Resource icon

Add preview text for first post in thread list

Jake Bunce

Well-known member
Jake Bunce submitted a new resource:

Add preview text for first post in thread list - Rather than a popup preview, it is inline in the thread listing.

Hack.

library/XenForo/ControllerPublic/Forum.php

Add the red code:

Rich (BB code):
	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'...

Read more about this resource...
 
Thank you for this, have this on my vb forum and was thinking that my users have to get used to not having it when I switch.
I have not tested it yet, sorry for asking before that.
Is it removing line breaks from the preview to keep it compact?
Will this slow a 5 000 000 posts forum down?
 
Is it removing line breaks from the preview to keep it compact?

No.

You can change that if you want. The template edit uses nl2br (new line to break):

Admin CP -> Appearance -> Templates -> thread_list_item

Remove the blue code (from the original red code) to remove line breaks from the preview text:

Rich (BB code):
			<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>

Will this slow a 5 000 000 posts forum down?

The impact is not nothing. It adds an extra join to the query that fetches thread records. And it does some extra processing to render the previews.

I would say the impact is not enough to matter.
 
I have now tried this out on a test forum, and it is looking good. I customized the template a bit.
It seems like closed and sticky threads aren't working, could that be correct?
 
Sorry to bother you with another question. What do I have to remove to not get the preview popup on the title?
 
It seems like closed and sticky threads aren't working, could that be correct?

I don't know if you missed that. I have been trying to figure it out but haven't been able to. I think it can be something missing in the editings of the .php files!?

I am very grateful for all the help I have gotten so far with this. This is a prefect mod for my site once I transfer over.
 
It is working well for me in 1.3

It is just the sticky threads that is not working, I was wrong about the closed ones, they are working, anyone have an idea how to solve the sticky ones?
 
My users have been using this for almost a month since my conversion from vb. And they like it a lot, the only complain they got is that it is not working on New threads list.
They haven't mentioned Watched threads list, not working their either, in both these cases it doesn't seem to be a template problem, but a .php file problem.
If anyone could help me solve this I and my users would be very happy.
 
It is working well for me in 1.3

It is just the sticky threads that is not working, I was wrong about the closed ones, they are working, anyone have an idea how to solve the sticky ones?
I might have solved the problem with sticky threads, mind you, I have no idea what I am doing ;)
I replaced the original change by @Jake Bunce in View.php with the following:
PHP:
        // 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']);
            }
        }
        foreach ($this->_params['stickyThreads'] 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']);
            }
        }
Think it works but maybe it could be done in another way?
 
  • Like
Reactions: Epi
Hello,

Has there been any development with this? Does it work with Sticky threads and does it work on Watched Threads page?

Thank you :)
 

Similar threads

Back
Top Bottom