India in 2050: The world’s second-largest economy—and its hundredth-poorest nation – The South First | News, Politics, Sports, Entertainment & Live Updates
${author.name}

`;
});
} else {
authorsHTML = `

No author information available

`;
}

// Additional content
let additionalContent = `

`;

// Append new article with additional content
$(‘#articles-container’).append(`

${response.data.title}

${response.data.meta_description}


Make Us Your Preferred Source on Google
${response.data.content}

${additionalContent}

`);

currentPostId = response.data.id;
excludedPosts.push(currentPostId);

updateMetaTags(response.data);
} else {
console.log(‘No more articles to load.’);
$(window).off(‘scroll’);
}
},
error: function (xhr, status, error) {
console.error(‘AJAX error:’, error);
},
complete: function () {
isLoading = false;
},
});
}

function fetchPreviousArticle(currentPostId) {

$.ajax({
url: ‘/wp-json/custom/v1/previous-article’,
type: ‘GET’,
data: {
post_id: currentPostId,
category_id: categoryId,
},
success: function (response) {
console.log(‘AJAX response received:’, response);

if (response.success) {
$(‘#articles-container’).prepend(`

${response.data.title}

${response.data.content}

`);
currentPostId = response.data.id;
} else {
console.log(‘No previous articles to load.’);
$(window).off(‘scroll’); // Stop further loading
}
},
error: function (xhr, status, error) {
console.error(‘AJAX error:’, error);
},
complete: function () {
isLoading = false;
},
});
}

// Trigger fetch on scroll
let lastScrollTop = 0;
$(window).on(‘scroll’, function () {
let scrollTop = $(window).scrollTop();
let scrollHeight = $(document).height();
let windowHeight = $(window).height();

// Scroll down: Trigger fetch when reaching the bottom (or near the bottom)
if (scrollTop + windowHeight >= scrollHeight – 900) {
fetchNextArticle();
}
});

});

var lastScrollTop = $(window).scrollTop(); // Store initial scroll position

$(window).on(“scroll”, function () {
var currentScrollTop = $(window).scrollTop();

if (currentScrollTop = divTop && scrollPos ‘);
}

// Update the document title
document.title = decodedTitle; // This updates the page title shown in the browser’s tab

// Check if meta description exists, and update it
var metaDescription = $(“meta[name=’description’]”);

if (metaDescription.length) {
metaDescription.attr(“content”, newDescription); // Update the existing meta description
} else {
// If meta description doesn’t exist, create it and append to the section
$(“head”).append(”);
}

// Similarly, if you want to dynamically set the canonical URL as well
var newCanonicalUrl = data.canonical_url;

// Check if the canonical link exists
var canonicalLink = $(“link[rel=’canonical’]”);

if (canonicalLink.length) {
canonicalLink.attr(“href”, newCanonicalUrl); // Update the existing canonical URL
} else {
// If canonical link doesn’t exist, create it and append to the
$(“head”).append(”);
}

// Update keywords (if any)
if (data.keywords) {
let keywordsMeta = $(“meta[name=’keywords’]”);
if (keywordsMeta.length) {
keywordsMeta.attr(“content”, data.keywords);
} else {
$(“head”).append(”);
}
}

history.pushState(null, decodedTitle, data.link);
gtag(‘config’, ‘G-2EJFH5VVDZ’, {
‘page_title’: decodedTitle,
‘page_path’: data.link
});

} else {
console.log(‘No more articles to load.’);
$(window).off(‘scroll’); // Stop further loading
}
},
error: function (xhr, status, error) {
console.error(‘AJAX error:’, error);
},
complete: function () {
isLoading = false;
},
});

}



Share.
Leave A Reply

Exit mobile version