Social share buttons are very important for the blog CMS, through which any visitor can share the blog link on their social account. Here we are creating complete dynamic blog CMS from the first part " how to create a blog from scratch in PHP" . We can also use social share icons or images instead of social share buttons. You already know about SEO. This is also the technique of SEO by which the rank of blog CMS can be increased. Here we will create a button for four social networking websites, on which any visitor can easily share. Let's talk about the social sites for which we are building the social share button.
1. Facebook - Who is not known about Facebook nowadays and Facebook is a social networking site on which the blog website can be easily populated. We will create a Facebook share button here using which any user can share a blog post on Facebook.
2. Twitter - Twitter is another social networking site on which you can share any blog post and increase the rank of your blog website. The share buttons for twitter can be easily created by PHP and MYSQL.''
3. LinkedIn - LinkedIn is another professional social networking site on which posts of your website can be famous. Social share buttons can also be easily added for LinkedIn.
4. Pinterest - Pinterest is another top-level social website on which any link with an image can be published. This is one of the best social networking site that works to rank blogs in Google or other search engines. Social share buttons can also be easily added to the blog website for Pinterest.
Let's now learn how to create share buttons for different social websites.
How to create a share button for facebook in PHP?
Creating the share button for Facebook is very important, for that, you should know the Facebook share URL, only then you can easily create a share button using PHP and MYSQL. Let's understand the Facebook share the link.
We use share.php file and URL of the current page blog post. We can use the current slug of the blog post and use it in the URL.
How to add the twitter social share button?
We can add the twitter share button using a twitter share URL. Every social site provides a share URL path.
http://twitter.com/share?text=Visit the link &url=https://technosmarter.com/add-social-share-button-for-twitter &hashtags=technosmarter,php,programming,tutorials,codes,examples,language
You can use tags with blog post slug in PHP. Add your website URL with blog post slug and create tags.
You can fetch related tags from the MYSQL database using PHP.
How to make a social share button for LinkedIn?
Linkedin is another professional platform to share the blog post. You can use the linkdin.com share link below.
How to create a Pinterest share button link?
Pinterest is one of the best image sharing platforms where you can share your website link with an image.
You can use Pinterest share link in your blog post
Let’s back to the Blog. We are creating a complete CMS from scratch.
Let’s understand the code lines.
In the code above, we can define own base URL path. We are storing blog post slug in the slug variable and article id in another variable. We will use articleId in the next tutorial.
Add the code lines at line 65 after the content(Or where you
want to display the share icons).
<a target="_blank" href="http://www.facebook.com/sharer.php?u=<?php echo $baseUrl.$slug; ?>"> <img src="assets/images/facebook.png" >
<a target="_blank" href="http://twitter.com/share?text=Visit the link &url=<?php echo $baseUrl.$slug; ?>&hashtags=blog,technosmarter,programming,tutorials,codes,examples,language,development">
<img src="assets/images/twitter.png" >
<a target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo $baseUrl.$slug; ?>"> <img src="assets/images/linkedin.png" >
<a target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php echo $baseUrl.$slug; ?>">
<img src="assets/images/pinterest.png" >
We are using social share icons instead of social share buttons.
Download the social share icons and paste them in the blog/assets/images folder.
Paypal payment form with email, invoice generator in PHP website | Scripts
Student result management system for school and college in PHP website
Payment form by PayUmoney gateway with GST invoice,email | PHP software