Last active
August 7, 2022 19:06
-
-
Save frontend-coder/817082fec11d2864f6fd0ae3607efac1 to your computer and use it in GitHub Desktop.
46. Створити віджет Share на сторінці поста #wordpress
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
function ale_share($type = 'fb') { | |
echo ale_get_share($type); | |
} | |
/** | |
* Get link for sharing | |
* | |
* @param string $type | |
* @return string | |
*/ | |
function ale_get_share($type = 'fb', $permalink = false, $title = false) { | |
if (!$permalink) { | |
$permalink = get_permalink(); | |
} | |
if (!$title) { | |
$title = get_the_title(); | |
} | |
global $post; | |
$excerpt = get_the_excerpt(); | |
$image_url = get_the_post_thumbnail_url($post->ID,'full'); | |
switch ($type) { | |
case 'twi': | |
return 'http://twitter.com/home?status=' . esc_attr($title) . '+-+' . esc_url($permalink); | |
break; | |
case 'fb': | |
return 'http://www.facebook.com/sharer.php?u=' . esc_url($permalink) . '&t=' . esc_attr($title); | |
break; | |
case 'goglp': | |
return 'https://plus.google.com/share?url='. urlencode(esc_url($permalink)); | |
break; | |
case 'vk': | |
return 'http://vkontakte.ru/share.php?url='. urlencode(esc_url($permalink)).'&title='.esc_attr($title).'&description='.esc_attr($excerpt); | |
break; | |
case 'pin': | |
return 'http://pinterest.com/pin/create/button/?url='. urlencode(esc_url($permalink)).'&description='.esc_attr($excerpt).'&media='.urlencode(esc_url($image_url)); | |
break; | |
case 'red': | |
return 'http://reddit.com/submit?url='. urlencode(esc_url($permalink)).'&title='.esc_attr($title); | |
break; | |
case 'lin': | |
return 'https://www.linkedin.com/shareArticle?mini=true&url='. urlencode(esc_url($permalink)).'&title='.esc_attr($title).'&summary='.esc_attr($excerpt); | |
break; | |
default: | |
return ''; | |
} | |
} |
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
<?php | |
if(function_exists('ale_get_share')){ | |
if(ale_get_option('blog_share_icons')!=='hide'){ ?> | |
<div class="share_icons"> | |
<?php $ale_share_platforms = ale_get_option('share_platforms'); | |
$ale_icon = ''; | |
foreach ($ale_share_platforms as $key => $value){ | |
switch ($key) { | |
case 'fb' : | |
$ale_icon = 'fa-facebook'; | |
break; | |
case 'twi' : | |
$ale_icon = 'fa-twitter'; | |
break; | |
case 'goglp' : | |
$ale_icon = 'fa-google-plus'; | |
break; | |
case 'lin' : | |
$ale_icon = 'fa-linkedin'; | |
break; | |
case 'red' : | |
$ale_icon = 'fa-reddit-alien'; | |
break; | |
case 'pin' : | |
$ale_icon = 'fa-pinterest'; | |
break; | |
case 'vk' : | |
$ale_icon = 'fa-vk'; | |
break; | |
} | |
if($value == '1'){ ?> | |
<a href="<?php echo esc_url(ale_get_share($key)); ?>" class="ale_share_icon ale_<?php echo esc_attr($key); ?>_icon" onclick="window.open(this.href, 'Share this post', 'width=600,height=300'); return false"><i class="fa <?php echo esc_attr($ale_icon); ?>" aria-hidden="true"></i></a> | |
<?php } | |
} | |
?> | |
</div> | |
<?php } | |
}?> |
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
if(function_exists( 'ale_get_share' )) { | |
<a href="<?php echo esc_url(ale_get_share('fb')); ?>" class="ale_share_icon ale_<?php echo esc_attr('fb'); ?>_icon" onclick="window.open(this.href, 'Share this post', 'width=600,height=300'); return false"><?php esc_html_e('fb', 'domain') ?></a> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment