Display Topics / Replies in a custom .php file

XF is a lot for a novice PHP programmer to learn at the beginning. I'd suggest dissecting the PHP trying to break it or get it to do other things post-finishing to understand it. (y)
 
Yep spot on, the only way i learn is trial and error.. so having it put on a plate for me while helpful in the short term is not helping me in the long term.. the xf code is kinda scary tho when you come from a wp background but after some trial and error i can see how powerful this is.. Again TY.. im sure to throw plenty more questions out there but in return will do what i can do assist others.

Again to everyone who helped TY..
 
XF Code > WP code. I can't stand developing for Wordpress. If you'd like, I can comment that code to explain what each line does.

I think i have the bare idea of it for now.. this is my current code.. in which i am sure to continue to modify as i am now considering displaying an attachment also lol.

PHP:
<?php

$threadModel = XenForo_Model::create('XenForo_Model_Thread');
$conditions = array();
$fetchOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST,
                    'order' => DESC,
                    'limit' => 8);
$threads = $threadModel->getThreadsInForum(2, $conditions, $fetchOptions);
foreach ($threads AS $threadId => $thread) {
    if ($threadModel->canViewThread($thread,$thread)) {
      echo ('<div class=messageList"><div class="entry-meta subHeading categoryStrip"><a href="' . XenForo_Link::buildPublicLink('canonical:threads', $thread) . '">' . XenForo_Helper_String::wholeWordTrim($thread['title'], 48) . '</a> <p>' . XenForo_Helper_String::wholeWordTrim($thread['message'], 440) . '</p> <span style="float:right; margin-right:60px">Viewed: ' . $thread['view_count'] . '</span><br /></div></div>');
    }
}

Notice the 'order' => DESC, <-- that was all me lmao.. Thanks tho got a good starting point to work with now as for the .css side of things i got that covered.

Regards, Darren
 
And it's also not the array key"order' !
PHP:
if (!empty($fetchOptions['order']))
        {
            $orderBySecondary = '';

            switch ($fetchOptions['order'])
            {
                case 'title':
                case 'post_date':
                case 'view_count':
                    $orderBy = 'thread.' . $fetchOptions['order'];
                    break;

                case 'reply_count':
                case 'first_post_likes':
                    $orderBy = 'thread.' . $fetchOptions['order'];
                    $orderBySecondary = ', thread.last_post_date DESC';
                    break;

                case 'last_post_date':
                default:
                    $orderBy = 'thread.last_post_date';
            }
            if (!isset($fetchOptions['orderDirection']) || $fetchOptions['orderDirection'] == 'desc')
            {
                $orderBy .= ' DESC';
            }
            else
            {
                $orderBy .= ' ASC';
            }

            $orderBy .= $orderBySecondary;
        }
 
Its FANTASTIC to see 2 members really going over and above board to help another member..

Kinda reminds me of how things used to be on here at the start..

Great help guys you have helped restore a little faith in forums...

Regards..

Couldn't of had said it better myself.. altho i did try lol.. I am very very thankful for the assistance and in future weeks and months i will be doing the same. Awesome to see a solid community !!

And again, Thanks to all who helped.. really made my day (as sad as that is lol).. Cheers
 
Am I reading the $fetchOptions properly? Isn't the orderDirection not set in his latest code and therefore DESC? Wouldn't this mean that the line 'order' => DESC isn't actually doing anything?
 
It is doing something => throwing an error (at least it should:D )


And even if it would be "desc" it would have at least 1 side effect=>

$fetchOptions['order'] isn't empty, so it's getting the code from this part=>
PHP:
if (!empty($fetchOptions['order']))
{
....

default:$orderBy = 'thread.last_post_date';
$orderBy .= ' ASC';
 
Hi, all...

Could this code be added to the bottom of any PHP file or can it only run within some sort of XF wrapper. If not, is there some way to modify it so that this can be done?

To put it more concretely, I run a MediaWiki wiki. Could I paste code like the above into the bottom of the appropriate PHP file (the skin file is the appropriate one, I believe, but I can figure that out on my own) and have it output the list of threads? In the long term, I'd like a list of threads that include links to a given Wiki page automatically generated at the bottom of every wiki page. This would, of course, require additional code, but hopefully it makes it clearer what I am trying to do.
 
PHP:
$fetchOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST,'order' => DESC,'limit' => 8);

($thread['post'],


correction of my last statement:
it will THROW ONLY in debugmode an error!

if debugmode isn't active, it works^^


DESC will be handled as constant (yes it's missing , but php is handling is at string => the result is , it's using "DESC" as order value, that's also why
$foo[baz] == $foo['baz'] is true without active debug mode (and the strict error level)^^


(don't know how to explain it correct on english :( )


that's also why you should work & develop always with active debug mode!
 
Debug mode has been on for this:

81Poymh.png


I am not seeing any errors with the DESC part.. once i added it the threads started displaying in the required order, without it the new threads just get added after each other.

In the interest of saving my going insane.. what would the correct code look like if someone was smart enough to be able to produce a error free version ? lol
 
Thanks bud :) I am trying my best bare with me. I can see why that was still working now.. so ive picked up something from that.. Thanks again.
 
Hi, all...

Could this code be added to the bottom of any PHP file or can it only run within some sort of XF wrapper. If not, is there some way to modify it so that this can be done?

To put it more concretely, I run a MediaWiki wiki. Could I paste code like the above into the bottom of the appropriate PHP file (the skin file is the appropriate one, I believe, but I can figure that out on my own) and have it output the list of threads? In the long term, I'd like a list of threads that include links to a given Wiki page automatically generated at the bottom of every wiki page. This would, of course, require additional code, but hopefully it makes it clearer what I am trying to do.
Forest they way that ExpertPixels is doing things, is using the XF application code, and inserting the query results into it. You couldn't just stick the .php at the bottom of any old .php page and have it magically work.
 
Decided to attempt this in a WordPress page. It worked okay but there are some slight changes needed.

Here is the image before making any coding changes ... bbcode and quote fixes are needed.

XenForo Forum Posts I Tux Reports Testing.webp
 
Getting BBCode to format is (well, should be) easy. :) Its a matter of instantiating XenForo_BbCode_Formatter_Base and calling the necessary rendering functions.

Example:
PHP:
$formatter = XenForo_BbCode_Formatter_Base::create('Base'); //see my guide for this explaination

$parser = new XenForo_BbCode_Parser($formatter);
$formatter->parse($message);

Note: You should always use the XenForo_BbCode_Formatter_Base::create($class) method so that various support functionality is added (smilies, bbcode cache, etc.) before rendering happens.
 
Last edited:
Note: You should always use the XenForo_BbCode_Formatter_Base::create($class) method so that various support functionality is added (smilies, bbcode cache, etc.) before rendering happens.

Thank you. I was just going through the Parse.php to see what was happening.
 
Top Bottom