1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add preview text for first post in thread list

Rather than a popup preview, it is inline in the thread listing.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff 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.

    Read more about this resource...
    Amin Sabet, MR.MB, time and 2 others like this.
  2. santamo

    santamo Active Member

    fine. thanks. 11223344.png
  3. ge66

    ge66 Active Member

    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?
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member


    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:

    			<div class="secondRow">
    				<div class="text">
    					<blockquote>{xen:string nl2br, {xen:helper wordtrim, $thread.messageParsed, $xenOptions.discussionPreviewLength}}</blockquote>
    				<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">
    							<xen:foreach loop="$thread.lastPageNumbers" value="$pageNumber">
    								<a href="{xen:link threads, $thread, 'page={$pageNumber}'}">{$pageNumber}</a>
    				<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>
    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.
    ge66 likes this.
  5. ge66

    ge66 Active Member

    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?
  6. 3rd AnGle

    3rd AnGle Well-Known Member

    Will we be able to do this on the xenporta recent thread block instead?
  7. ge66

    ge66 Active Member

    Sorry to bother you with another question. What do I have to remove to not get the preview popup on the title?
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Find and remove {xen:if $thread.hasPreview, PreviewTooltip} in the thread_list_item template.
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That would be a different code modification.
  10. ge66

    ge66 Active Member

    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.
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Those are probably queried separately and so must be handled separately.

    This guide is mainly intended as a code example.
  12. time

    time Active Member

    Last edited: Nov 29, 2013
  13. sami simo

    sami simo Well-Known Member

    is this working in 1.3 ?
  14. ge66

    ge66 Active Member

    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?
  15. ge66

    ge66 Active Member

    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.
  16. ge66

    ge66 Active Member

    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:
            // 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?
    Epi likes this.
  17. Lexy

    Lexy Active Member

    maybe plugin for this to not add nothing manualy
  18. Anton_Bodryachkom

    Anton_Bodryachkom Active Member

    is this work with 1.4 version?
  19. xfstyle

    xfstyle Member

    @Jake Bunce
    How to Add preview text for last post in thread list

    please, help me

  20. RichardKYA

    RichardKYA Well-Known Member


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

    Thank you :)

Share This Page