Add a Preview text for threads in Xenforo

Today we are going to discuss how to add a inline text preview of your threads.

What I mean is that when you hover over a thread you will have a box that pop’s up and shows you a short description like the following:

inline

So instead of having that it will move it to underneath the thread title like so:

inline2

So this one can be a bit difficult to do but I will walk you step by step. So we are going to go to file manager or you can use FileZilla to do this. We will be editing PHP files of the core of Xenforo. Please make sure that you make copies and back up your forum before you do anything to it.

First step is to navigate to where your Xenforo folder is and click on it. You will then navigate to the following file:

/libary/xenforo/ControllerPublic/Forum.php

On or about line 316  you should see the following:

protected function _getThreadFetchElements

That is the section we are looking for scroll down a bit more to line 329

The line has the following code in it:

'join' => XenForo_Model_Thread::FETCH_USER,

 

after FETCH_USER and before the comma you will put the following:

| XenForo_Model_Thread::FETCH_FIRSTPOST

Please make sure that you include the | or pipe as it is called.

So it will look like this:

'join' => Xenforo_Model_Thread::FETCH_USER | XenForo_Model_Thread::FETCH_FIRSTPOST,

Make sure that you save it and re-upload and overwrite if you chose to do it that way.

We will now go back to our root Xenforo folder and navigate  to the following file:

library/XenForo/ViewPublic/Forum/View.php

You will look for line 15

It will start with :

public function renderHTML()

after the ); in the beginning you will add the following code:

// 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']);
			}
		}

Make sure that it’s after the ); on a new line. So it will look like the following code:

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']);
			}
		}
	}

Make sure that you save it and overwrite the file so it’s new.

Now we are done editing files. We will log into our Admin CP and navigate to Appearance and Templates it looks like this:

inline3

We are looking for thread_list_item

Once you find it it will look like this:

inline4

So click on it and you will see the following screen:

inline5

You are looking for this element:

<div class=”secondRow”>

Right after that you are going to add the following code:

<div class="text">
<blockquote>{xen:string nl2br, {xen:helper wordtrim, $thread.messageParsed, $xenOptions.discussionPreviewLength}}</blockquote>
				</div>

It should look like the following image:

inline6

Make sure that you click Save All Changes.

Then navigate to a Category and look at your threads and you should see the following:

inline2

All done!

If you have any questions or comment’s please feel free to ask away!

Looking for quality XenForo hosting? Check out Arvixe Web Solutions

Tags: , , , , , , , | Posted under XenForo | RSS 2.0

Author Spotlight

Keith Pottratz

Hello My Name is Keith Pottratz. I have been working with computers for over a decade. It's my personal hobby something that I love and enjoy doing. I went to school for Computer Science, and have spent many years self teaching my self various things. I have ton's of experience in HTML,CSS, PHPBB,CPanel,CMS software, blogging software and various other systems and enviroments. My favorite thing to do though is backend developing. I find it to be a growing and ever evolving beast and I love learning about it. I look forward to giving as much knowledge as I can and help.

Leave a Reply

Your email address will not be published. Required fields are marked *