Help Center
Find answers or browse our knowledge base.
Latest Questions
Adding Post to Feed
Addon Example — Custom Post Type (Books)
This example shows how to create a new post_type called book that injects activity items into the main feed. It uses the post_to_feed.php hook, plus two feed templates.
Step 1 — Declare the post type
Each addon defines its post type name (for example book). You store posts in the posts table with post_type='book'. Extra metadata (e.g. authors, price, cover) goes in addon tables such as books and posts_books.
Example SQL when creating a post:
INSERT INTO posts (user_id, post_type, text) VALUES (123, 'book', '');
Link it to a book record:
INSERT INTO posts_books (post_id, book_id) VALUES (456, 789);
Step 2 — Hook: post_to_feed.php
- File: /modules/books/hooks/post_to_feed.php
- Purpose: enrich posts with book fields before rendering in the feed.
Core logic (simplified):
This attaches to each post:
- book_title, book_title_full
- book_description, book_description_short
- book_price
- cover_url, book_url
- book_author, book_author_url, book_authors[]
Step 3 — Feed Story Template
- File: /content/themes/{theme}/templates/books/tabs/feed.story.tpl
- Purpose: render the activity line (actor + verb + object).
{elseif $_post.post_type == "book"} {__("suggested a book")} {if !empty($_post.book_author)} {__("by")} {$_post.book_author|escape} {/if} {/elseif}
Step 4 — Feed Content Template
- File: /content/themes/{theme}/templates/books/tabs/feed.content.tpl
- Purpose: render the book card content.
{if $_post.post_type == "book"}{/if}{$_post.book_title|escape}
{if !empty($_post.cover_url)}{/if}
{$_post.book_description_short}
{__("View Book")}
Step 5 — Test
- Create a new post with post_type = book.
- Verify post_to_feed.php enriches the feed array with book fields.
- Feed should now show:
- Story line: “User suggested a book by Author”
- Content card: Title, Cover, Description, Button
Summary
To create a new feed-aware post type, every addon needs:
- post_to_feed.php in /modules/{addonid}/hooks/
- feed.story.tpl and feed.content.tpl in /content/themes/{theme}/templates/{addonid}/tabs/
- Posts saved into the posts table with post_type='yourtype'
- Optional extra tables (like books) for metadata
This same pattern works for Books, Forums, Jobs, Blogs, Market, etc. Just swap the metadata fields and templates.
Was this answer helpful?
How could it be better?
What went wrong?