I created a simple system for liking posts. 1 like = 1 IP #1383
Unanswered
Grosso2020
asked this question in
General
Replies: 2 comments 3 replies
-
Excellent work, but I would have chosen to serialize to PHP:SQLite3 (because of A.C.I.D and transactional safety) |
Beta Was this translation helpful? Give feedback.
1 reply
-
@Grosso2020 - If I can suggest few things:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi guys.
I created a simple like system for Publii CMS in PHP+JS without using a database and would like to share with the community. Bug comments and code improvements are welcome.
Likes work when you click on the button both in a list of posts and in single posts. 1 like is counted per user and the data is recorded in the likes.json file.
{"7":{"46.163.139.18":true},"9":{"46.163.139.18":true},"5":{"46.163.139.18":true}}
1. I created two PHP files and added them to the root of the site
like.php
get_likes.php
2. I created the JS code and placed it in Custom HTML in the Footer
3. I created the CSS code and placed it in Custom CSS
4. I created an empty likes.json file and put it in the root of the site
I deny access to the likes.json file
Create a .htaccess file in the root of the site and add a rule:
5. Display a counter and a like button in the list of posts and single posts and recommended posts. I edited files in themes mono-override.
- List of posts index.hbs.
After
{{#if @config.custom.cardsDate}}...{{/if}}
- Single post posts.hbs.
After
<time datetime="{{date createdAt 'YYYY-MM-DDTHH:mm'}}">...</time>
- And below I added the code to the recommended posts section
{{#if @config.post.displayRelatedPosts}}...{{/if}}
After
<time datetime="{{date createdAt 'YYYY-MM-DDTHH:mm'}}">...</time>
6. Results
- List of posts
- Single post
- Recommended posts
I hope it will be useful to someone.
Beta Was this translation helpful? Give feedback.
All reactions