Display Topics / Replies in a custom .php file

The above code by xf_phantom will limit it to 5 threads, are you receiving more? The second snippet from xf_phantom (fixed below) should trim the content to 48 words:
PHP:
<?php

echo ('<div class="entry-meta"><a href="' . XenForo_Link::buildPublicLink('canonical:threads', $thread) . '">' . XenForo_Helper_String::wholeWordTrim($thread['title'], 48) . '</a> <span style="float:right; margin-right:60px">Viewed: ' . $thread['view_count'] . '</span><br /></div>');

If you provide the actual code you are using, I may be able to provide more help.

Everything is working fine now and ive found a bunch of options / variables i can use but am struggling to get the actual content to display, the thread titles are displaying fine just no content... The idea being i could display a snippet of the thread under each title... I am coming from a WP background and with that it was very easy to set a post excerpt length whereas i am struggling with xf.. I will keep mucking around until i suss it out.

Thanks everyone for your help.
 
This is my complete news.php file:

PHP:
<?php

$threadModel = XenForo_Model::create('XenForo_Model_Thread');$options = array('limit' => 5);$threads = $threadModel->getThreadsInForum(2,array(), $options);
foreach ($threads AS $threadId => $thread){
if ($threadModel->canViewThread($thread,$thread)){
   
    echo ('<div class="entry-meta"><a href="' . XenForo_Link::buildPublicLink('canonical:threads', $thread) . '">' . XenForo_Helper_String::wholeWordTrim($thread['title'], 48) . '</a> <p> First Post Should Go Here </p> <span style="float:right; margin-right:60px">Viewed: ' . $thread['view_count'] . '</span><br /></div>');
}
}

Note the "First Post Should Go Here" <-- I would like the first post of each thread to display a excerpt of the full first post in here.. again much like the xenporta addon allows with it's front page portal..

Thanks in advance for further assistance on this, almost got it to where i need it.. I can dress it up with .css later on but for now any help with the functionality is greatly appreciated.
 
ok guys i am lost.. still trying to wrap my head around this.. I am losing to much time with this so i may have to open my wallet and have someone create a .php file for me :(

@xf_phantom & @King Kovifor what's it going to cost me ?? lmao i am struggling to wrap my head around this.. sorry to be a pain in the behind.

I am still playing around with this but don't seem to be getting anywhere.
 
This should accomplish what you want, printing out the first 48 words of the post:
PHP:
<?php

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

$options = array('limit' => 5);
$joinOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST);

$threads = $threadModel->getThreadsInForum(2, $joinOptions, $options);
foreach ($threads AS $threadId => $thread) {
    if ($threadModel->canViewThread($thread,$thread)) {
      echo ('<div class="entry-meta"><a href="' . XenForo_Link::buildPublicLink('canonical:threads', $thread) . '">' . XenForo_Helper_String::wholeWordTrim($thread['title'], 48) . '</a> <p>' . XenForo_Helper_String::wholeWordTrim($thread['post'], 48) . '</p> <span style="float:right; margin-right:60px">Viewed: ' . $thread['view_count'] . '</span><br /></div>');
    }
}
 
@King Kovifor Thanks for your ongoing help with this one.. ive just tested your latest code found here and it's still not doing as intended. I will continue to play around with this..

Thanks again tho, really appreciate any assistance on this.. slowly getting there... if anything i am learning a lot of xf.

Regards, Darren
 
DreM608.png


This is what the new code is doing.. i just can't seem to produce a excerpt of the opening post which is what i really would like to show. basically the idea is a lot like what they have done here: http://demo.extralicense.com/ i just don't need a full portal / cms like they have and would rather not reply on other addons that's why i am being a little picky and trying to make it happen myself.

Regards, Darren
 
and btw
the code is wrong, sorry
join and limit have to be in the fetchOptions

PHP:
$conditions = array();
$fetchOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST,
                     'limit' => 5);

$threads = $threadModel->getThreadsInForum(2, $conditions, $fetchOptions);
 
you need to output the post

And where is the magical button to make that happen ?? wow so in over my head here... back to some tutorials me thinks.. I would run with a existing portal but for what i need they are a little advanced.. anyways i don't want to keep hassling you guys so i may flip and just run with simpleportal if i can't tweak my current code. Thanks all.
 
that's why i use always var_dump instead of echo as first:D

then you see all the available array keys
PHP:
[1] => Array
(
[thread_id] => 1
[node_id] => 2
[title] => test
[reply_count] => 0
[view_count] => 1
[user_id] => 1
[username] => dev
[post_date] => 1372415253
[sticky] => 0
[discussion_state] => visible
[discussion_open] => 1
[discussion_type] =>
[first_post_id] => 1
[first_post_likes] => 0
[last_post_date] => 1372415253
[last_post_id] => 1
[last_post_user_id] => 1
[last_post_username] => dev
[prefix_id] => 0
[message] => dassad
[attach_count] => 0
)
and so you know that the message is available in $thread['message'] and not $thread['post']
 
Ok Thank you gentlemen !!!!

Finally working.. I got something to play around with now..

@xf_phantom cheers :) i see what you were getting at using the var_dump <-- i didn't understand the use of that originally now i see how / why that is so hand :P ok finally on the ball now.. Thank you.
 
ok one little issue.. how would one make the latest thread appear at the top.. the way it's rendering now is pushing the the latest thread to the bottom of the page.

PHP:
<?php

$threadModel = XenForo_Model::create('XenForo_Model_Thread');
$conditions = array();
$fetchOptions = array('join' => XenForo_Model_Thread::FETCH_FIRSTPOST,
                    'limit' => 5);
$threads = $threadModel->getThreadsInForum(2, $conditions, $fetchOptions);
foreach ($threads AS $threadId => $thread) {
    if ($threadModel->canViewThread($thread,$thread)) {
      echo ('<div class="entry-meta"><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>');
    }
}

new screenshot:

Hhau1mB.png


EDITED: added updated code & attached a new screenshot
 
then add the order and orderDirection options to your fetchOptions array

I would really suggest to take a look at the XenForo_Model_Thread file to see how it works and what conditions and options you can include
 
ok you guys have been more than helpful.. i'll sty and sort this out myself.. but please do note i do appreciate your help.. will be sending small donations a select few as soon as possible, Cheers guys.

@xf_phantom Thanks.. I managed to reorder the threads all on my very own.. OMG !! haha thanks and sorry for being annoying this assistance / help should put me in good shape..
 
If we give you all the necessary code, you'll never learn it yourself:P
(at as far as i've understood it from your posts and the conversations, you're trying to learn it)
 
Top Bottom