How to show a forum in a page

How to show a forum in a page

Fuhrmann

Well-known member
Fuhrmann submitted a new resource:

How to show a forum in a page (version 1.0) - This tutorial will explain how to show a forum (thread list) inside a page.

This tutorial will explain how to show a forum (thread list) inside a page. I'll not explain why this, or why that, but all the code necessary is commented.

And this is the final result:


View attachment 26005


I strongly recommend you to read my others tutorials to know better how XenForo works:

How to show a forum in a page...

Read more about this resource...
 
I'm getting the following error.

Code:
Fatal error: Cannot use object of type XenForo_Template_Public as array in /path/to/community/library/NodesAsTabs/ControllerPublic/Page.php on line 21

If I put in a bad forum id then the page will load - a good forum id gives me the above error.

Any ideas?
 
Hi I get the same Error as Iph mentioned above:

Code:
Fatal error: Cannot use object of type XenForo_Template_Public as array in /home/onlinegilde/public_html/library/NodesAsTabs/ControllerPublic/Page.php on line 21

But I have no Idea what to do. Maybe someone could help!

EDIT:

I forget to say, that if I disable NodeAsTabs everything works just fine, so there must be a conflict. But i have just startet coding with Xenforo and I have no idea where to search for the problem.


benny
 
It's because jack's code

PHP:
$nodeId = 0;
if (!empty($viewParams['page']['node_id']))
$nodeId = $viewParams['page']['node_id'];
if (!empty($viewParams['forum']['node_id']))
$nodeId = $viewParams['forum']['node_id'];
if (!empty($viewParams['category']['node_id']))
$nodeId = $viewParams['category']['node_id'];
and the code in the article
PHP:
        /* Create the template to show the threads, with all the params requireds */
        $threadList = new XenForo_Template_Public('thread_list', $controllerResponse->params);
 
        /* Set the param 'forum' with the rendered template so we can use in our page */
        $response->params['forum'] = $threadList;

use the same variable ( forum)



you could change


$response->params['forum'] = $threadList;

to

$response->params['forums2'] = $threadList;


and in template


<xen:require css="discussion_list.css" />
<div class="discussionList">
{xen:raw $forums2}
</div>
 
It almost works. Changed line 47 to
Code:
$response->params['xf_apple_forum'] = $threadList;

And matched in Page Options.

Sadly, this only shows the 4 threads in one forum ($threadsToShow) and does not include links to the child forums below it.
 
It almost works. Changed line 47 to
Code:
$response->params['xf_apple_forum'] = $threadList;

And matched in Page Options.

Sadly, this only shows the one forum and not the ones below it.
and because of your sub forum problem=>


check XenForo_ControllerPublic_Forum::actionIndex
PHP:
 'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay($forum, 0),
and

XenForo_ViewPublic_Forum_View::renderHtml

there you'll see how it works:)
 
thx for confirming that this was the problem:)

I'm learning with everyone's help here!

Looking at your other post now and trying to figure out what's happening in that code so I can show child forums.

I should say:

Code:
$request->setParam('node_id', 114);

The above sets the node_id ... but I'm not sure if that can be changed to an array (is that even the right term.?.. LOL)
 
I love this thread... I am using a page to display video via fwplayer.. works great! I cannot display forum on a page and display video on the same page. please advise

EDIT - This code presents a video, located below the video is a message forum which is also displayed in the nodelist.

Code:
<xen:require css="discussion_list.css" />
<div class="discussionList">
 
<div id="container">Loading the player ...</div>
<script type="text/javascript">
jwplayer("container").setup({
autostart: "false",
flashplayer: "/jwplayer/player.swf",
file: "/jwplayer/video.mp4",
height: 540,
width: 940
});
</script>
<br />
 
<div class="discussionList">
 
{xen:raw $forum}
 
</div>
 
The last DIV tag places the forum on your page

http://newsecondcity.com/pages/theater-showcase/

Code:
<xen:require css="discussion_list.css" />
 
<script src="http://newsecondcity.com/jwplayer/jwplayer.js"></script>
<script>jwplayer.key="nfrBKE1rkvkQIcJb1v25jvg8rAfhdfOb9TuHrw=="</script>
 
<div id="showcase">Loading the player...</div>
<script type="text/javascript">
    jwplayer("showcase").setup({
        file: "http://content.bitsontherun.com/videos/3XnJSIm4-kNspJqnJ.mp4",
        width: 940,
        height: 540,
        image: "http://content.bitsontherun.com/thumbs/3XnJSIm4-640.jpg",
        title: "Sintel trailer"
    });
</script>
<br />
 
<div class="discussionList">
 
    {xen:raw $forum}
 
</div>
 
Errors on 1.2

Code:
Server Error

Missing argument 2 for XenForo_Controller::preDispatch(), called in C:\xampp\htdocs\12\library\ShowAForum.php on line 25 and defined
XenForo_Application::handlePhpError() in XenForo/Controller.php at line 300
XenForo_Controller->preDispatch() in ShowAForum.php at line 25
ShowAForum::showAForumInPage()
call_user_func_array() in XenForo/ControllerPublic/Page.php at line 46
XenForo_ControllerPublic_Page->actionIndex() in XenForo/FrontController.php at line 337
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
XenForo_FrontController->run() in C:/xampp/htdocs/12/index.php at line 13

missing $controllerName
 
Changed line 25 to get around the missing $controllerName but am now getting an array_slice error

New Line 25
PHP:
$controllerForum->preDispatch('index', 'XenForo_ControllerPublic_Forum');

Line still giving error (line 38):
PHP:
$controllerResponse->params['threads'] = array_slice($controllerResponse->params['threads'], 0, $threadsToShow - 1);

Can comment out the above line and all is well .. otherwise .. get this error.

Code:
XenForo_Application::handlePhpError()
array_slice() in ShowResearchNotes.php at line 38
ShowResearchNotes::showResearchNotesInPage()
call_user_func_array() in XenForo/ControllerPublic/Page.php at line 46
XenForo_ControllerPublic_Page->actionIndex() in XenForo/FrontController.php at line 337
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
XenForo_FrontController->run() in /path/community/index.php at line 13
 
This seems pretty useful when you only have one forum and want to bypass the forum category page. Is this the best way to do that? Or is there a feature in the control panel which can eliminate the list of category nodes if there is only one (so you can go straight to the thread list)?
 
Top Bottom