1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Displaying latest post information on PHP page

Discussion in 'XenForo Development Discussions' started by AUSFIFA, May 5, 2014.


    AUSFIFA Member

    I've followed this tutorial and have placed a "Latest Posts" feed on my PHP home page outside of Xenforo:

    It works fine and all, but I'd like to get some more information about the latest post:
    - The last post author
    - The last post date

    So esentially it'll end up looking like this:
    This is an example thread... by User123 2 minutes ago
    Another thread underneath... by User456 18 minutes ago
    ANOTHER THREAD!!!! by AnotherUser 2 hours ago

    Also, I'd like to change the links to anchor to the latest post in the thread, rather than the first post.

    And would it also be possible to get a specific user's latest posts? Basically the same thing as above but only restricted to a user rather than the entire forum.

    I've tried looking for information on how to use this type of code to access Xenforo outside of the forum but there doesn't seem to be any documentation anywhere, which is kind of odd.

    Any help would be greatly appreciated.

  2. LPH

    LPH Well-Known Member

    You'll want to start by looking at the database -> xf_thread

    Screen Shot 2014-05-04 at 8.17.56 PM.png

    This lets you know that the SELECT portion should include the items you want.

    Next, to display these items you would use $thread['last_post_username'] ...

    AUSFIFA Member

    Well that was dumb of me, I didn't think it was connected to the MySQL database.

    I'm having an issue displaying this information though. I've modified my SELECT to include last_post_username:

    $sql_forum = "SELECT `title`, `thread_id`, `view_count`, `reply_count`, 'last_post_username' FROM `xf_thread` WHERE `node_id` IN ($node_id_list) ORDER BY `last_post_date` DESC LIMIT {$limit}";

    And then I've echo'd it like this:

    And the output is coming out as "last_post_username". Same thing happens with "last_post_date". It outputs the name of the column and not the actual data.
    The odd thing is, when I change it to {$thread['reply_count']}, it's printing the number properly. What am I doing wrong?
  4. LPH

    LPH Well-Known Member

    Watch the difference between quotes and ticks in your SQL. Also echo without interpolate and the curly bracket.

    AUSFIFA Member

    Lol yep that fixed it, I just changed the quotes to ticks in the SQL statement.

    Another two questions:
    1. The date comes out in this format: 1398292340. What would be the best way to convert that to say "x minutes ago?". Or hours/days ago if goes that long.

    2. How do I change the links to point to the last post in the thread? This is the code that builds my links:
    $threadUrl =$forum_url. XenForo_Link::buildPublicLink('threads', $thread);
    LPH likes this.

Share This Page