import wixData from ‘wix-data’ ;
const collectionName = ‘Blog/Posts’ ;
const fieldToFilterByInCollection = ‘hashtags’ ;
$w . onReady ( async function () {
const today = new Date ();
$w ( “#text53” ). text = today . toLocaleDateString ();
$w ( “#text54” ). text = today . toLocaleTimeString ();
await loadDataToRepeater ( “breaking” )
});
function loadDataToRepeater ( selectedCategories = ) {
let dataQuery = wixData . query ( collectionName )
if ( selectedCategories . length > 0 ) {
dataQuery = dataQuery . hasSome ( fieldToFilterByInCollection , selectedCategories )
}
dataQuery
. find ()
. then ( results => {
console . log ( results );
if ( results . items . length > 0 ) {
let firstItem = results . items [ 0 ];
let secondItem = results . items [ 1 ];
$w ( ‘#button12’ ). label = firstItem . title ;
$w ( ‘#button12’ ). link = firstItem . postPageUrl ;
if ( secondItem === undefined ) {
$w ( ‘#button13’ ). label = $w ( ‘#button12’ ). label ;
$w ( ‘#button13’ ). link = firstItem . postPageUrl ;
}
else { $w ( ‘#button13’ ). label = secondItem . title ;
$w ( ‘#button13’ ). link = secondItem . postPageUrl ;
}
console . log ( firstItem );
$w ( ‘#columnStrip25’ ). show ();
$w ( ‘#button13’ ). hide ();
$w ( ‘#button12’ ). hide ();
slide ();
} else {
console . log ( “no data found” );
$w ( ‘#columnStrip25’ ). hide ();
}
} )
. catch ( ( err ) => {
console . log ( err );
} );
}
function slide (){
let toggle = true ;
const animationCycle = 5000 ;
const animationDuration = 4000 ;
const hideDelay = 0 ;
setInterval (() =>
{
if ( toggle ) {
$w ( ‘#button12’ ). show ( ‘slide’ , {
duration : animationDuration , direction : ‘right’
}
);
}
else {
$w ( ‘#button13’ ). show ( ‘slide’ , {
duration : animationDuration , direction : ‘right’
}
);
}
setTimeout (() => {
if ( toggle ) {
$w ( ‘#button13’ ). hide ( ‘slide’ , { duration : 1000 });
} else {
$w ( ‘#button12’ ). hide ( ‘slide’ , { duration : 1000 });
}
toggle = ! toggle ;
}, hideDelay );
}, animationCycle );
}
This code worked properly for last one year and suddenly started misbehaving.
It used to grab the title of latest 2 blog posts and display the same in the button text. but unfortunately it is not showing the titles of latest post but shows titles of old blog posts.
please help me to get the titles of the latest posts.
Thank you.