Correct Params to show thread_list outside XenForo

LPH

Well-known member
I'm close to rendering the thread list outside XenForo but know the params are not complete. I'd like to be able to set the node_id, number of threads to show, and see replies, etc.

PHP:
        $dependencies = new XenForo_Dependencies_Public();

        $dependencies->preLoadData();

        /* Get the visitor param */
        $visitor = XenForo_Visitor::getInstance();

        $styleId = $visitor['style_id'];

        if ( $styleId > 0 ) {
            XenForo_Template_Public::setStyleId( $styleId );
        } else {
            XenForo_Template_Public::setStyleId( 1 );
        }

        $languageId = $visitor['language_id'];

        if ( $languageId > 0 ) {
            XenForo_Template_Abstract::setLanguageId( $languageId );
        } else {
            XenForo_Template_Abstract::setLanguageId( 1 );
        }

        $params = array(
            'visitor'      => $visitor,
            'node_id'       =>'5',
            //'threads'       => '',
            'totalThreads'  => '5'
        );

        $template = $dependencies->createTemplateObject( 'thread_list', $params );

        echo $template->render();

The attached image shows what is rendered.

The struggle is figuring out the $params. Is there an "easy" way to figure these out?

If it isn't just the params, do you see something else needed?
 

Attachments

  • Screen Shot 2014-11-16 at 5.56.51 AM.webp
    Screen Shot 2014-11-16 at 5.56.51 AM.webp
    30.7 KB · Views: 15
Look at on forum_view:
Code:
<div class="discussionList section sectionMain">
    <xen:include template="thread_list" />
</div>

If you using thread_list template so you're missing there html
Code:
<div class="discussionList section sectionMain">

So you should include that HTML before template `thread_list` :)
 
Thank you @Nobita.Kun but I'm still not understanding how to get params. My code is returning the node_id for the forum threads to show. The print_r confirms this. However, the message "there are no threads to display" is showing as well as a "loading" message.

I agree that my code is not taking care of the html and css. I was going to work on that after figuring out why the threads are not showing. But, I'm not sure how to get the html div tag information to render ...

But first ... where are the threads? Why are they not returning? Is this because the params are not correct?
 
Thank you @Nobita.Kun but I'm still not understanding how to get params. My code is returning the node_id for the forum threads to show. The print_r confirms this. However, the message "there are no threads to display" is showing as well as a "loading" message.

I agree that my code is not taking care of the html and css. I was going to work on that after figuring out why the threads are not showing. But, I'm not sure how to get the html div tag information to render ...

But first ... where are the threads? Why are they not returning? Is this because the params are not correct?
Hi. In the code you show above. I didn't notice anywhere you get threads params? Is that full code of your project?

Maybe help: https://xenforo.com/community/resources/how-to-show-a-forum-in-a-page.307/
 
Hi. In the code you show above. I didn't notice anywhere you get threads params? Is that full code of your project?

I didn't show the full code because I was trying to understand the params array. You might notice my code had the threads commented out because I wasn't sure what to put there. :)
 
I made progress ! :D

It turns out the obvious was really missing from my posted code.

PHP:
$threadModel= XenForo_Model::create( 'XenForo_Model_Thread' );


Then link that to the params.

Anyway ... now comes the next challenge which @Nobita.Kun pointed out the other day; that is, the html / css is incorrect.

1. The links are missing the relative path. Instead of lph/community/members the link only has lph/members

2. The CSS is not rendering.

Here is my of a code (shown with past attempts)

PHP:
        //$number_of_posts = $instance['numberposts'];

        $threadModel = XenForo_Model::create( 'XenForo_Model_Thread' );

        $forum = $instance['forumnumber'];

        $conditions = array();

        $fetchOptions = array(
            'join' => XenForo_Model_Thread::FETCH_FIRSTPOST,
            'order' => 'post_date',
            'orderDirection' => 'desc',
            'limit' => 5
        );

        $threads = $threadModel->getThreadsInForum( $forum, $conditions, $fetchOptions );

        $feature_node_id = $instance['show_forum_number'];

        echo 'The node_id is ' . $feature_node_id ;

        $dependencies = new XenForo_Dependencies_Public();
        $dependencies->preLoadData();

        /* Get the visitor param */
        $visitor = XenForo_Visitor::getInstance();

        $styleId = $visitor['style_id'];

        if ( $styleId > 0 ) {
            XenForo_Template_Public::setStyleId( $styleId );
        } else {
            XenForo_Template_Public::setStyleId( 1 );
        }

        $languageId = $visitor['language_id'];

        if ( $languageId > 0 ) {
            XenForo_Template_Abstract::setLanguageId( $languageId );
        } else {
            XenForo_Template_Abstract::setLanguageId( 1 );
        }

        $params = array(
            'visitor'      => $visitor,
            'node_id'  => $feature_node_id,
            'threads'   => $threads,
            'forum'     => 'raw',
            'totalThreads' => '5',
            'perPage' => '20',
            'page' => '',
            'order' => '1',
            'orderDirection' => ''
        );

        // $template = "<div class='discussionList section sectionMain'>";

        $template = $dependencies->createTemplateObject( 'thread_list', $params );

        // $template .= "</div>";

        echo $template->render();

Questions:
1. What am I missing to get the html/css to render properly? Is there an example somewhere to get css rendering outside XF?

2. How do I solve the relative links problem when using templates?

--- As always ---
Thank you !

Sometimes I feel like :( and other times like :mad: and finally it's more like :oops: until I get to this :cry: which is always changed to :cool: after someone in this community helps :D


Update: I should clarify that the using the inspect code on the page shows

PHP:
<form action="inline-mod/thread/switch" method="post" class="DiscussionList InlineModForm" data-cookiename="threads" data-controls="#InlineModControls" data-imodoptions="#ModerationSelect option">
	
	

	<dl class="sectionHeaders">
		<dt class="posterAvatar"><a><span>Sort by:</span></a></dt>
		<dd class="main">
			<a href="." class="title"><span>Title</span></a>
			<a href="." class="postDate"><span>Start Date</span></a>
		</dd>
		<dd class="stats">
			<a href="." class="major"><span>Replies</span></a>
			<a href="." class="minor"><span>Views</span></a>
		</dd>
		<dd class="lastPost"><a href="."><span>Last Message</span></a></dd>
	</dl>

	<ol class="discussionListItems">		

<li id="thread-197" class="discussionListItem visible  " data-author="LPH">

	<div class="listBlock posterAvatar">
		<span class="avatarContainer">
			<a href="members/lph.1/" class="avatar Av1s" data-avatarhtml="true"><img src="styles/default/xenforo/avatars/avatar_s.png" width="48" height="48" alt="LPH"></a>
			
		</span>
	</div>

	<div class="listBlock main">
		<div class="titleText">
			<h3 class="title">
				<a href="threads/review-but-choosing-xenword.197/" title="" class="" data-previewurl="">Review - But Choosing XenWord</a>
			</h3>
			
			<div class="secondRow">
				<div class="posterDate muted">
					<a href="members/lph.1/" class="username" dir="auto" title="Thread starter">LPH</a><span class="startDate">,
					<a href="threads/review-but-choosing-xenword.197/" class="faint"><abbr class="DateTime" title="Go to first message in thread" data-time="1415923008" data-diff="537458" data-datestring="Nov 13, 2014" data-timestring="3:56 PM">Nov 13, 2014 at 3:56 PM</abbr></a></span>

					
				</div>

				<div class="controls faint">	
					
				</div>
			</div>
		</div>
	</div>

	<div class="listBlock stats pairsJustified" title="Members who liked the first message: 0">
		<dl class="major"><dt>Replies:</dt> <dd>0</dd></dl>
		<dl class="minor"><dt>Views:</dt> <dd>3</dd></dl>
	</div>

	<div class="listBlock lastPost">
		
			<dl class="lastPostInfo">
				<dt><a class="username" dir="auto"></a></dt>
				<dd class="muted"><a href="posts/" title="Go to last message" class="dateTime"><span class="DateTime" title="Nov 19, 2014 at 9:14 PM">Nov 19, 2014</span></a></dd>
			</dl>
		
	</div>
</li>
 
Last edited:
Let me re-word my question and see if this makes more sense.

Is there a path params that can be added so that the full board URL is returned rather than a relative path?

PHP:
$template= $dependencies->createTemplateObject( 'thread_list', $params );
 
I'm back to looking at this code and cannot find a way around the relative path when using a template. Does anyone have any ideas or suggestions for where I can look?

I'm getting close - but need to figure out a way to get the paths correct. This image shows a forum being displayed in a WordPress widget area, modifying the CSS of sectionHeaders to display:none.

The paths go to http://lph/threads/... instead of http://lph/community/threads/...

PHP:
$template= $dependencies->createTemplateObject( 'thread_list', $params );
echo $template->render();

Screen Shot 2014-12-30 at 11.44.10 PM.webp
 
Top Bottom