Page 1 of 1

How add a sharing button on Static pages ?

Posted: Fri Feb 19, 2021 6:43 pm
by Panther
If I want to add a sharing button (like Facebook or Twitter, Whatsapp, etc....) on entries (articles) I have to add a code like this on entry-default.tpl:

<a href="http://www.facebook.com/sharer.php?u={$ ... :the_title}" target="_blank"><img src="/Immagini/facebook.png" border="0" alt="Facebook" width="42" height="42"></a>

<a href="http://twitter.com/share?text={$subject ... :post_link}" target="_blank"><img src="/Immagini/twitter.png" border="0" alt="Twitter" width="42" height="42" ></a>

But adding this on Static pages this doesn't work, ad ex. Facebook reports this error:
href should represent a valid URL

and Twitter (a white page).

On Static pages what type of code I have to add ? It have to be different from ({$id|link:post_link}&title={$subject|tag:the_title}") ?

P.S.
Obviously using sharethis or addthis or addtoany buttons works, but I'd like to use my own sharing buttons.

Thank you

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 2:19 am
by Tongara
On the plugin you made last year, I did add a thing on how to make it work on static pages. The same change will work here.

Please see this post: viewtopic.php?f=4&t=144&start=10#p453

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 3:50 pm
by Lubomír Ludvík
Add "Share this:" to template with Awesome font
View this source and copy with .css link to entry-default.tpl

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 4:26 pm
by Panther
Tongara wrote: Sat Feb 20, 2021 2:19 am On the plugin you made last year, I did add a thing on how to make it work on static pages. The same change will work here.

Please see this post: viewtopic.php?f=4&t=144&start=10#p453
Hi, I have tried to modify in:

<a href="http://www.facebook.com/sharer.php?u={$ ... :the_title}" target="_blank"><img src="/Immagini/facebook.png" border="0" alt="Facebook" width="36" height="36"></a>

Then going of mouse on facebook button appears this:
http://www.facebook.com/sharer.php?u={$ ... :the_title}

and Facebook window reports error:
href should represent a valid URL


at contrary of articles where cliking of facebook button appears:
http://www.facebook.com/sharer.php?u=ht ... 0displaced


On Twitter button
<a href="http://twitter.com/share?text={$subject ... :page_link}" target="_blank"><img src="/Immagini/twitter.png" border="0" alt="Twitter" width="36" height="36" ></a>

the page appears completly white

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 5:38 pm
by Lubomír Ludvík
replace page_link with post_link

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 6:21 pm
by Tongara
Panther wrote: Sat Feb 20, 2021 4:26 pmHi, I have tried to modify in:

<a href="http://www.facebook.com/sharer.php?u={$ ... :the_title}" target="_blank"><img src="/Immagini/facebook.png" border="0" alt="Facebook" width="36" height="36"></a>

Then going of mouse on facebook button appears this:
http://www.facebook.com/sharer.php?u={$ ... :the_title}

and Facebook window reports error:
href should represent a valid URL


at contrary of articles where cliking of facebook button appears:
http://www.facebook.com/sharer.php?u=ht ... 0displaced


On Twitter button
<a href="http://twitter.com/share?text={$subject ... :page_link}" target="_blank"><img src="/Immagini/twitter.png" border="0" alt="Twitter" width="36" height="36" ></a>

the page appears completly white
Very strange!

My code is like so (It uses fontawesome, but ignore that, as it';s not the point):

Code: Select all

 <a href="http://www.facebook.com/sharer.php?u={$id|link:page_link}&title={$subject|tag:the_title}" target="_blank">
<i class="fab fa-facebook-square fa-lg"></i></a>
<a href="http://twitter.com/share?text={$subject|tag:the_title}&url={$id|link:page_link}" target="_blank">
<i class="fab fa-twitter-square fa-lg"></i></a>
<a href="whatsapp://send?text={$subject|tag:the_title} {$id|link:page_link}" data-action="share/whatsapp/share" target="_blank">
<i class="fab fa-whatsapp-square fa-lg"></i></a>
<a href="fb-messenger://share/?link={$id|link:page_link}&app_id=IDHERE" target="_blank">
<i class="fab fa-facebook-messenger fa-lg"></i></a>
<a href="http://pinterest.com/pin/create/link/?url={$id|link:page_link}&description={$subject|tag:the_title}" count-layout="horizontal" target="_blank">
<i class="fab fa-pinterest-square fa-lg"></i></a>
<a href="http://www.tumblr.com/share/link?url={$id|link:page_link}" target="_blank">
<i class="fab fa-tumblr-square fa-lg"></i></a>
<a href="https://reddit.com/submit?url={$id|link:page_link}&title={$subject|tag:the_title}" target="_blank">
<i class="fab fa-reddit-square fa-lg"></i></a>
<a href="mailto:?subject={$subject|tag:the_title}&amp;body={$id|link:page_link}" title="{$subject|tag:the_title}">
<i class="fas fa-envelope-square fa-lg"></i></a>
Check if yours matches up to that. I've tested mine again just now and it 100% works. I've copied this code directly from my static.tpl.
Lubomír Ludvík wrote: Sat Feb 20, 2021 5:38 pm replace page_link with post_link
On static pages, page_link is appropriate. post_link is used for blog posts, as shown here:

Code: Select all

<a href="http://www.facebook.com/sharer.php?u={$id|link:post_link}&title={$subject|tag:the_title}" target="_blank">
<i class="fab fa-facebook-square fa-lg"></i></a>
<a href="http://twitter.com/share?text={$subject|tag:the_title}&url={$id|link:post_link}" target="_blank">
<i class="fab fa-twitter-square fa-lg"></i></a>
<a href="whatsapp://send?text={$subject|tag:the_title} {$id|link:post_link}" data-action="share/whatsapp/share" target="_blank">
<i class="fab fa-whatsapp-square fa-lg"></i></a>
<a href="fb-messenger://share/?link={$id|link:post_link}&app_id=IDHERE" target="_blank">
<i class="fab fa-facebook-messenger fa-lg"></i></a>
<a href="http://pinterest.com/pin/create/link/?url={$id|link:post_link}&description={$subject|tag:the_title}" count-layout="horizontal" target="_blank">
<i class="fab fa-pinterest-square fa-lg"></i></a>
<a href="http://www.tumblr.com/share/link?url={$id|link:post_link}" target="_blank">
<i class="fab fa-tumblr-square fa-lg"></i></a>
<a href="https://reddit.com/submit?url={$id|link:post_link}&title={$subject|tag:the_title}" target="_blank">
<i class="fab fa-reddit-square fa-lg"></i></a>
<a href="mailto:?subject={$subject|tag:the_title}&amp;body={$id|link:post_link}" title="{$subject|tag:the_title}">
<i class="fas fa-envelope-square fa-lg"></i></a>

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 7:43 pm
by Panther
Now it works, this is because I didn't use static.tpl (as you), but I used another file.
I've read again your post to understand where was my error.
Thank you very much to all.

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 8:43 pm
by Tongara
Ah, glad you got it working! :)

Re: How add a sharing button on Static pages ?

Posted: Sat Feb 20, 2021 9:18 pm
by Panther
If this can help you, this works better

http://www.facebook.com/sharer/sharer.php (with this every page is shared well)

than this

http://www.facebook.com/sharer.php

At the end I use this code:

Code: Select all

<a href="http://www.facebook.com/sharer/sharer.php?u={$id|link:page_link}&title={$subject|tag:the_title}" target="_blank"><img src="/Immagini/facebook.png" border="0" alt="Facebook" width="36" height="36"></a>

Re: How add a sharing button on Static pages ?

Posted: Sun Feb 21, 2021 2:06 pm
by Tongara
Panther wrote: Sat Feb 20, 2021 9:18 pm If this can help you, this works better

http://www.facebook.com/sharer/sharer.php (with this every page is shared well)

than this

http://www.facebook.com/sharer.php

At the end I use this code:

Code: Select all

<a href="http://www.facebook.com/sharer/sharer.php?u={$id|link:page_link}&title={$subject|tag:the_title}" target="_blank"><img src="/Immagini/facebook.png" border="0" alt="Facebook" width="36" height="36"></a>
Oh nice, I'm always up for using something better if it turns up, so I appreciate it. I have now updated my code on my blog.

Glad we could help one another! haha