Search code examples
apostrophe-cms

How to load the last three added data from sub pages into home page


I have a page contains cards with title and image and descriptions, and I can add as much as I want, then I want to load this data in home page but I need it to shows only the last 3 added on that page


Solution

  • Assuming the content of your cards is powered by an apostrophe-pieces subclass you want to use apostrophe-pieces-widgets to dynamically pull the last 3 pieces and add them to any page (in your case the home page).

    This tutorial details getting up and running with apostrophe-pieces-widgets https://docs.apostrophecms.org/apostrophe/tutorials/getting-started/reusable-content-with-pieces#displaying-pieces-with-widgets

    After you have your widget in your template, you want to configure the widget to Select from All.. and limit it to 3.

    Apostrophe pieces widget's configuration to pull most recently added

    You can demo the editing experience of this type of widget by visiting the Apostrophe Open Museum demo and working with the below widget, which is on the home page

    Apostrophe Open Museum example of a pieces widget