Display Topics / Replies in a custom .php file

All the magic really happens in the formatters. And it's an insane amount of tree parsing (parent <-> relationships) that also determine parsing. That's where you'd want to really look if you want to see the magic.
 
This is the code I placed into a php file, as a WordPress child theme template file. A new page in the WordPress admin panel is created and the template file is chosen from the drop down. This does not trim the forum post.

However, it would be nice to change this code so that an admin chooses (promotes) a thread ....

PHP:
<?php
/**

Template Name: xffrontpage
*/

get_header(); ?>

<div id="primary">
   <div id="content" role="main">
     <div id="mainstory">
       <?php
         $threadModel = XenForo_Model::create( 'XenForo_Model_Thread' );

         $conditions = array();

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

         $threads = $threadModel->getThreadsInForum( 2, $conditions, $fetchOptions ); // 2 is the node

         foreach ( $threads AS $threadId => $thread ) {

          if ( $threadModel->canViewThread( $thread, $thread ) ) {

               $formatter = XenForo_BbCode_Formatter_Base::create();
               $parser = new XenForo_BbCode_Parser($formatter);
               $html = $parser->render($thread['message']);
               echo $html .'<br /><br /><hr>';
          }
         }
       ?>

     </div><!-- #mainstory -->
   </div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>
 
It's no secret that i am a awesome xf coder ;) so if you need a hand feel free to shoot me a PM.

Asides from being a good smart arse i am a WP theme expert, if you would like a hand with your WP @LPH or anyone else for that matter.. shoot me a PM that i can help you with.

Darren

EDIT: Nice work on your site LPH :) looks good, the more internal links the better as you have a hell of a lot of OBL that should help balance that out.. not only looks good but is very helpful for the end-user.
 
Last edited:
EDIT: Nice work on your site LPH :) looks good, the more internal links the better as you have a hell of a lot of OBL that should help balance that out.. not only looks good but is very helpful for the end-user.

Thank you for the compliment and offer.

The Page Rank flow is 5%. Sadly it is an interpretation because all those "outbound links" are actually the network of TRN sites all in one WP install. :)
 
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.
That was what I was worried about. ...but...
Decided to attempt this in a WordPress page. It worked okay but there are some slight changes needed.
Perhaps I could do what LPH did? I mean, embedding in WP can't be that much different from embedding in MediaWiki.

LPH, what did you do to ensure access to XenForo_Model, etc?
 
Promoting threads could be quite a big feature and would take fundamental changes to the above code.
 
Promoting threads could be quite a big feature and would take fundamental changes to the above code.

I believe there is code for promoting from an XF thread to XenPorta. I'll take a look at how that is done. Maybe there are some clues in that code.
 
That was what I was worried about. ...but...

Perhaps I could do what LPH did? I mean, embedding in WP can't be that much different from embedding in MediaWiki.

LPH, what did you do to ensure access to XenForo_Model, etc?
You would need to use the kotomi shell and pop it into a media wiki <div> tag
There would be some formatting clean up.

If you just want to promote a thread into WP or media wiki that's super easy. But if you want all the comments to come over too, automagically, that's a small amount of work n
 
If you just want to promote a thread into WP or media wiki that's super easy.

I've read others say the same but never seen any code shared to get from XF to WP. I believe the above code pulls XF thread first post - and so

1. Code to pull a select thread_id
2. Code to write first post to the WP database would be the next step.

Since XenScripts adds a column to WP for thread_id then writing that information to the WP database is already taken care of ....
 
You can pull a thread by id using:
PHP:
<?php
$threadModel = XenForo_Model::create('XenForo_Model_Thread');
$fetchOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST);
$threadModel->getThreadById($id, $fetchOptions);

However, that is essentially 1 query per thread. You can manually write that for several threads to minimize or optimize.
 
  • Like
Reactions: LPH
You can pull a thread by id using:
PHP:
<?php
$threadModel = XenForo_Model::create('XenForo_Model_Thread');
$fetchOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST);
$threadModel->getThreadById($id, $fetchOptions);

However, that is essentially 1 query per thread. You can manually write that for several threads to minimize or optimize.
The only thing you need to watch if are doing this automagically is avoiding have spam posted to WP and ensuring you adhere to forum permissions. Don't want private forums pushed to WP.

But if you want to do it manually, with a button so admins or mods can decide to push it, then it's much less worrisome.
 
But if you want to do it manually, with a button so admins or mods can decide to push it, then it's much less worrisome.

A button should show for admins to select the thread wanting to be promoted to a WordPress page or post.
 
The Kotomi script started playing up with 1.2 I thought i had my head around that script until 1.2 it was working fine before hand but now you can not use the wrapper out side of the install directory.. it needs to be installed in the xf installation dir.

mysite.com <-- kotomi index file
mysite.com/community/ <-- xf installed here

The above is how i was doing things prior to 1.2 but since 1.2 the script for some reason is not able to fetch the kotomi index file outside of the xf install dir.
 
Top Bottom