- Compatible XF Versions 1.x
- 1.0, 1.1, 1.2
I will teach you how to show a specific post in a XenForo page.
I strongly recommend you to read my others tutorials to know better how XenForo works.
Step 1 - Creating the code
Let's start by creating the code responsable to get the content of the post.
First thing you need to do is create a new file. You can place this file anywhere, but in this tutorial we will use a dedicated folder for it. Go to your_xenforo_root/library and create this directory structure:
------|ShowAPost *create this folder*
---------|View.php *create this file*
---------|Index.php *create this file*
The Index.php file will be the file that we will declare the callback class and method to our page. Copy and past the following code:
Do not forget to change the postId to what you want:
Now, open the View.php file. This file will parse all bbcode in the post message.
Copy and paste inside the file:
Now we'll create the page that will show the post you want to show. Go to AdminCP -> Applications -> Create new Page. In the next page, you have some fields to fill. Use the information below:
- Url Portion: showapost
- Title: Show a Post (The title doest not matters, because we'll use the thread title)
- Description: Show a post inside a page
- Template HTML:
- PHP Callback: ShowAPost_Index::showAPostInPage
Save the page.
Step 3 - Testing
Now go to your forum list. You should see the page node there:
Click to enter the page and see the result. Your post is now being displayed inside a page!
- If you want to show the page title and not the thread title, just change the Template HTMl of the page to this:
- If you want to hide the breadcrumbs put the following code at the TOP of the template HTML of the page: