-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Berridge
committed
Jul 31, 2012
1 parent
1759177
commit a20f661
Showing
6 changed files
with
199 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
# Simple Social Sharing Buttons | ||
|
||
An often overlooked method of implementing social sharing buttons (without counters) on your site. Super lightweight without any external loading or JavaScript, fully customisable using CSS alone. A PHP version for WordPress is also included. | ||
|
||
**Check out the demo here: http://builtbyboon.com/posed/Simple-Social-Sharing-Buttons/** | ||
|
||
**Read all about it: http://builtbyboon.com/blog/simple-social-sharing-buttons** | ||
|
||
built by Boon – given away free | ||
|
||
If you have questions or put this to use then hit me up on Twitter (@mattberridge). | ||
# Simple Social Sharing Buttons | ||
|
||
An often overlooked method of implementing social sharing buttons (without counters) on your site. Super lightweight without any external loading or JavaScript, fully customisable using CSS alone. WordPress plugin also included. | ||
|
||
**Check out the demo here: http://builtbyboon.com/posed/Simple-Social-Sharing-Buttons/** | ||
|
||
**Read all about it: http://builtbyboon.com/blog/simple-social-sharing-buttons** | ||
|
||
built by Boon - given away free | ||
|
||
If you have questions or put this to use then hit me up on Twitter (@mattberridge). | ||
|
||
## Using the WordPress plugin | ||
|
||
Download and upload `simple-social-sharing.php` into your plugins folder and activate it. To call the buttons anywhere in your theme, use the function `<?php simple_social_sharing('mattberridge'); ?>` including your Twitter username. | ||
|
||
If you wish to show/hide any of the buttons individually, add a further attribute e.g. `<?php simple_social_sharing('mattberridge', '1,0,1'); ?>` | ||
|
||
These are toggles for each button in the order Twitter, Facebook, Google+. `1` means show, `0` means hide. | ||
|
||
I have also created a shortcode (to be used in the content body) which follows the same form e.g. `[simple-social-sharing twitter="mattberridge" display="1,0,1"]` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/* | ||
Plugin Name: Simple Social Sharing | ||
Plugin URI: https://github.com/mattberridge/Simple-Social-Sharing-Buttons | ||
Description: Super lightweight social sharing buttons (without counters) | ||
Author: built by Boon | ||
Author URI: http://builtbyboon.com | ||
*/ | ||
function simple_social_sharing($attr_twitter = null, $attr_items = null) { | ||
|
||
// parse variables | ||
$twitter_account = $attr_twitter; | ||
$item_toggles = $attr_items; | ||
|
||
// get post content and urlencode it | ||
global $post; | ||
$browser_title_encoded = urlencode(trim(wp_title('', false, 'right'))); | ||
$page_title_encoded = urlencode(get_the_title()); | ||
$page_url_encoded = urlencode(get_permalink($post->ID)); | ||
|
||
// create share items | ||
$share_items = array (); | ||
|
||
$item_twitter = array( | ||
"class" => "twitter", | ||
"href" => "http://twitter.com/share?text={$page_title_encoded}&url={$page_url_encoded}&via={$twitter_account}", | ||
"text" => "Share on Twitter" | ||
); | ||
$item_facebook = array( | ||
"class" => "facebook", | ||
"href" => "http://www.facebook.com/sharer.php?u={$page_url_encoded}&t={$browser_title_encoded}", | ||
"text" => "Share on Facebook" | ||
); | ||
$item_google = array( | ||
"class" => "google", | ||
"href" => "http://plus.google.com/share?url={$page_url_encoded}", | ||
"text" => "Share on Google+" | ||
); | ||
|
||
// test whether to display each item | ||
if($item_toggles) { | ||
// explode into array | ||
$item_toggles_array = explode(",", $item_toggles); | ||
// set each item on or off | ||
$show_twitter = $item_toggles_array['0']; | ||
$show_facebook = $item_toggles_array['1']; | ||
$show_google = $item_toggles_array['2']; | ||
} | ||
else { | ||
$display_all_items = 1; | ||
} | ||
|
||
// form array of relevant items | ||
if($show_twitter==1 || $display_all_items) { | ||
array_push($share_items, $item_twitter); | ||
} | ||
if($show_facebook==1 || $display_all_items) { | ||
array_push($share_items, $item_facebook); | ||
} | ||
if($show_google==1 || $display_all_items) { | ||
array_push($share_items, $item_google); | ||
} | ||
|
||
// if one or more items | ||
if(!empty($share_items)) { | ||
// create output | ||
$share_output = "<ul class=\"ss-share\">\n"; | ||
foreach($share_items as $share_item) { | ||
$share_output .= "<li class=\"ss-share-item\">\n"; | ||
$share_output .= "<a class=\"ss-share-link ico-{$share_item['class']}\" href=\"{$share_item["href"]}\" rel=\"nofollow\" target=\"_blank\">{$share_item['text']}</a>\n"; | ||
$share_output .= "</li>\n"; | ||
} | ||
$share_output .= "</ul>"; | ||
// echo output | ||
echo $share_output; | ||
} | ||
|
||
} | ||
|
||
// add shortcode to output buttons | ||
function simple_social_sharing_shortcode( $atts, $content = null ) { | ||
|
||
// parse variables / set defaults | ||
extract( shortcode_atts( array( | ||
'twitter' => '', | ||
'display' => '1,1,1', | ||
), $atts ) ); | ||
|
||
// output buttons | ||
$output_string = simple_social_sharing($twitter, $display); | ||
return force_balance_tags($output_string); | ||
} | ||
add_shortcode('simple-social-sharing', 'simple_social_sharing_shortcode'); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
/* | ||
Author : Boon | ||
URL : http://builtbyboon.com | ||
Twitter : http://twitter.com/mattberridge | ||
---------------------------------------*/ | ||
body { | ||
margin: 0; | ||
font: 1em/1.5 sans-serif; } | ||
|
||
.strip { | ||
background: #891434; | ||
color: #fff; | ||
padding: 1em 5%; | ||
|
||
p { | ||
text-align: left; | ||
font-size: 1.2em; } | ||
|
||
a { | ||
color: #fff; } | ||
|
||
} | ||
|
||
.container { | ||
width: 90%; | ||
margin: 2em auto; } | ||
|
||
/* -- Begin social sharing buttons | ||
------------------------------------------------------------- */ | ||
.share { | ||
padding-left: 0; | ||
list-style: none; } | ||
|
||
.share-item { | ||
display: inline; | ||
margin-right: 1em; } | ||
|
||
.share-link { | ||
/* crude button styles */ | ||
text-decoration: none; | ||
color: #444; | ||
font-weight: bold; | ||
padding: .5em .75em .5em 35px; | ||
background-color: #f5f5f5; | ||
border: 1px solid #ccc; | ||
border-radius: 2px; | ||
|
||
&:hover, | ||
&:active, | ||
&:focus { | ||
color: #891434; | ||
} | ||
} | ||
|
||
[class*="ico"] { | ||
display: inline-block; | ||
background-size: 16px 16px; | ||
background-repeat: no-repeat; | ||
background-position: 10px center; } | ||
|
||
.ico-facebook { | ||
background-image: url('http://www.facebook.com/favicon.ico'); | ||
} | ||
|
||
.ico-twitter { | ||
background-image: url('http://twitter.com/favicons/favicon.ico'); | ||
} | ||
|
||
.ico-google { | ||
background-image: url('https://ssl.gstatic.com/s2/oz/images/faviconr2.ico'); | ||
/* | ||
Author : Boon | ||
URL : http://builtbyboon.com | ||
Twitter : http://twitter.com/mattberridge | ||
---------------------------------------*/ | ||
body { | ||
margin: 0; | ||
font: 1em/1.5 sans-serif; } | ||
|
||
.strip { | ||
background: #891434; | ||
color: #fff; | ||
padding: 1em 5%; | ||
|
||
p { | ||
text-align: left; | ||
font-size: 1.2em; } | ||
|
||
a { | ||
color: #fff; } | ||
|
||
} | ||
|
||
.container { | ||
width: 90%; | ||
margin: 2em auto; } | ||
|
||
/* -- Begin social sharing buttons | ||
------------------------------------------------------------- */ | ||
.ss-share { | ||
padding-left: 0; | ||
list-style: none; } | ||
|
||
.ss-share-item { | ||
display: inline; | ||
margin-right: 1em; } | ||
|
||
.ss-share-link { | ||
/* crude button styles */ | ||
text-decoration: none; | ||
color: #444; | ||
font-weight: bold; | ||
padding: .5em .75em .5em 35px; | ||
background-color: #f5f5f5; | ||
border: 1px solid #ccc; | ||
border-radius: 2px; | ||
|
||
&:hover, | ||
&:active, | ||
&:focus { | ||
color: #891434; | ||
} | ||
} | ||
|
||
[class*="ico-"] { | ||
display: inline-block; | ||
background-size: 16px 16px; | ||
background-repeat: no-repeat; | ||
background-position: 10px center; } | ||
|
||
.ico-facebook { | ||
background-image: url('http://www.facebook.com/favicon.ico'); | ||
} | ||
|
||
.ico-twitter { | ||
background-image: url('http://twitter.com/favicons/favicon.ico'); | ||
} | ||
|
||
.ico-google { | ||
background-image: url('https://ssl.gstatic.com/s2/oz/images/faviconr2.ico'); | ||
} |
This file was deleted.
Oops, something went wrong.