Displaying blog posts

Currently I use JS to load blog posts from the database.The code is contained in a document.ready function. I want though the posts to be displayed even when JS is disabled…I will use PHP for that.

The issue is I do not know how to do it.
If for example I place PHP code below the document ready function in the same file then the blog posts will appear twice.
What can I do…how can I program for the above situation?

Is this a hand-crafted CMS or one of the regulars?

I can’t see why you need to use JS to show content, why not just use PHP across the board then you haven’t got to worry if JS isn’t enabled.


in this day and age you can pretty much assume that javascript is available, and can use an appropriate noscript section to tell those without javascript (enabled) that the site requires it. As the post that answered a related question on Stack Exchange said:

I think sacrificing functionality for 99% of users to accommodate 1% is sheer bloody mindedness.

This isn’t to say that you shouldn’t consider progressive enhancement techniques, but javascript is now so widely implemented that at least a major subset of it can be assumed to be present.

However as others have pointed out you can already load the content server-side in php and render it as part of the regular page, no need at all to use js/ajax to do this unless there are unusual requirements; for example, the page must update automatically when new posts are created etc, but really this goes beyond a javascript/ajax solution and more into web sockets if you want to implement that properly. IMHO, its best to do that with a good framework (React, Angular etc) that supports that style of rendering which makes it a little out of scope of this question.

1 Like

Be that as it may - and I’m sure there will be people along shortly who will dispute it, the main point is it doesn’t make a whole lot of sense to use JS to display data from a database, such as blog posts. This is much better done server-side.

1 Like

Well, I guess it’s a matter of choice and preference.

Personally, I try to always do Progressive Enhancement

For example, unless I didn’t always want the blog posts to show, I would have the backend serve them.

Then if I wanted to do some show-hide stuff I would use JavaScript to both hide and show.

Thought in fact, I probably wouldn’t use JavaScript for that now-a-days, because CSS alone can do it.

^ Exactly

1 Like

@Gandalf indeed, as I pointed out later in the post.

But my point there was that most of the high-end frameworks - including all frameworks that support the single page application paradigm - do assume that javascript is present on the client end and even require it.

To those still in denial, welcome to the 21st century… :slight_smile:

1 Like



I have concluded to go(at least for now) for the PHP only solution.The problem now is pagination…

How to code pagination icons/links.

Any help will be much appreciated.

I suggest you start a new topic for that in the PHP category.

You are right…thanks.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.