Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-09-19 07:30:08

Myusername
Member
Registered: 2019-12-12
Posts: 73

Correct way to "load more" articles with ajax?

Good Morning! A quick question…

I am designing a website on Textpattern that would like to use a “load more” button at the end of the article loop. The goal, of course, is to load more articles when clicked.

I did this by creating a form in json format with all the information of the articles I needed (title, body, author, etc.). Then, I used ajax to access that form and then display them in my loop.

However, in my research, tutorials generally pointed to a direct search of the database, never like I did.

So I was thoughtful. Is there a “right way” to do this? does anyone know anything about it?

Last edited by Myusername (2020-09-19 11:23:54)

Offline

#2 2020-09-19 12:50:48

etc
Developer
Registered: 2010-11-11
Posts: 3,934
Website

Re: Correct way to "load more" articles with ajax?

Myusername wrote #325960:

However, in my research, tutorials generally pointed to a direct search of the database, never like I did.

Could you develop on this? Are SQL servers capable of interpreting AJAX requests without any (say, PHP) interface?

Offline

#3 2020-09-19 21:41:58

Myusername
Member
Registered: 2019-12-12
Posts: 73

Re: Correct way to "load more" articles with ajax?

etc wrote #325967:

Could you develop on this? Are SQL servers capable of interpreting AJAX requests without any (say, PHP) interface?

I don’t think I expressed myself well. In fact when I said it directly from the database, I meant using PHP for that. However, without a json file to store the articles.

An example is this topic.

Maybe I will launch a shortcode that helps to include “load more” buttons with ajax in article_custom and article tags. But I would like to develop using best practices.

Offline

#4 2020-09-20 06:45:20

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,282
Website

Re: Correct way to "load more" articles with ajax?

I have seen txp sites with ajax loading of articles about 10 years ago. I never liked this type of endless scrolling, present in social media platforms, as the visitors never quite know where they can access the articles from, especially after the number of the articles increases.

Maybe my dislike is now intensified as I am relating endless scrolling to doomscrolling, but admittedly it would be interesting to see how it can be done using the latest txp version.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#5 2020-09-20 11:54:46

etc
Developer
Registered: 2010-11-11
Posts: 3,934
Website

Re: Correct way to "load more" articles with ajax?

Myusername wrote #325969:

An example is this topic. … But I would like to develop using best practices.

By no mean I pretend my practices are good, just sharing. The laziest way must be jQuery load method, when you retrieve what you need directly from a remote HTML page and insert it into your page. If the performance is important (or you just want to get rid of jQuery), then, I think, loading and processing JSON data instead is fine. Outputting JSON is quite easy with txp 4.8 via media-typed forms, but the client-side JS processing will be yours.

The example you cite is illustrated here, fwiw.

Offline

Board footer

Powered by FluxBB