Help Center

Find answers or browse our knowledge base.

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"}
  

{$_post.book_title|escape}

{if !empty($_post.cover_url)} {$_post.book_title|escape} {/if}

{$_post.book_description_short}

{__("View Book")}
{/if}

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:

  1. post_to_feed.php in /modules/{addonid}/hooks/
  2. feed.story.tpl and feed.content.tpl in /content/themes/{theme}/templates/{addonid}/tabs/
  3. Posts saved into the posts table with post_type='yourtype'
  4. 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?
You must login to vote.
0 found this helpful, 0 did not
Thank you for your feedback!

Related Articles

ScriptsTribe https://scriptstribe.com