Dynamic Pages Previous Next
Show info about previous and next dynamic pages

All Snippets
Instructions
Add Text or Image elements on the page
Set their ids same as the id of the fields you want to show, prefixed with prev or next.
For example, to show 'title' of previous and next items, set the ids of text boxes to #prevtitle and #nexttitle
New to our site? Please see our quick tutorial on how to work with our snippets
Setting | Description |
---|---|
$w.onReady(() => {
DynamicPagePreviousNext({
collectionId: 'DynamicPage',
fieldId: 'link-dynamic-page-title',
datasetId: '#dynamicDataset'
})
})
async function DynamicPagePreviousNext({datasetId:e,collectionId:t,fieldId:i}){
const a=$w(e);if(!a?.id)return;await a.onReadyAsync()
;const n=await a.getNextDynamicPage(),s=await a.getPreviousDynamicPage(),c=require("wix-data")
;let o;if(n){o=(await c.query(t).eq(i,n).find()).items;r(o.length&&o[0],"next")
}else{const e=$w("#nextbox");e?.id&&e.hide()}if(s){
o=(await c.query(t).eq(i,s).find()).items;r(o.length&&o[0],"prev")}else{
const e=$w("#prevbox");e?.id&&e.hide()}function r(e,t){
if(e)for(const[i,a]of Object.entries(e)){const e=$w("#"+t+i)
;if(e?.id)switch(e.show(),e.type){case"$w.Text":
Array.isArray(a)?e.text=a.join(", "):e.text=a;break;case"$w.Image":a&&(e.src=a)}
}}}

Title

Title