Dynamic Post Popups with URL Parameters

Thank you for your contribution, @Patric. I tried the solution from your referenced post earlier and it worked. However, it made designing the popup a bit tedious as it loaded all of my posts in the popup due to the query loop. Nonetheless, it worked as expected on the frontend. I also reached out to support and they provided me with a rather simple solution that worked for me. I am leaving it here in case someone else needs it.

Solution As received from Bricks Support

To open a popup via URL parameter, you have to write some custom JavaScript.
The core function is bricksOpenPopup

Example:

  • You must turn on the AJAX Popup
  • Place the dynamic data of the post that you wish to show inside the Popup template
  • Set condition to display this popup on your page
document.addEventListener("DOMContentLoaded", () => {
  // Get the ID from the hash
  let urlParams = new URLSearchParams(window.location.search);
  let postId = urlParams.get("postId") ?? false;

  if (postId) {
    // Your popup Id
    let popupId = 1234
    setTimeout(() => {
      // Open your popup with Context postId
      bricksOpenPopup(popupId, 0, {
        popupContextId: postId,
        popupContextType: "post",
      });
    }, 100);
  }
});
1 Like