admin管理员组文章数量:1410697
I am using this code to display social media share links at the top of my posts. Currently, they display fine on my pages and posts. Is there any way to get this to display also on my category pages? Another option that would work is getting the code to display everywhere below the H1 and content, I don't think there are any pages where I don't want these buttons so perhaps this is the easier solution.
Any guidance would be greatly appreciated ☺️
function crunchify_social_sharing_buttons($content) {
global $post;
if(is_singular() || is_home()){
// Get current page URL
$crunchifyURL = urlencode(get_permalink());
// Get current page title
$crunchifyTitle = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');
// $crunchifyTitle = str_replace( ' ', '%20', get_the_title());
// Get Post Thumbnail for pinterest
$crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
// Construct sharing URL without using any script
$twitterURL = '='.$crunchifyTitle.'&url='.$crunchifyURL.'&via=Crunchify';
$facebookURL = '.php?u='.$crunchifyURL;
$googleURL = '='.$crunchifyURL;
$bufferURL = '='.$crunchifyURL.'&text='.$crunchifyTitle;
$linkedInURL = ';url='.$crunchifyURL.'&title='.$crunchifyTitle;
// Based on popular demand added Pinterest too
$pinterestURL = '/?url='.$crunchifyURL.'&media='.$crunchifyThumbnail[0].'&description='.$crunchifyTitle;
// Add sharing button at the end of page/page content
$variable .= '<!-- Implement your own social sharing buttons without any JavaScript loading. No plugin required. Detailed steps here: -->';
$variable .= '<div class="crunchify-social">';
$variable .= '<a class="crunchify-link crunchify-twitter" href="'. $twitterURL .'" target="_blank">Twitter</a>';
$variable .= '<a class="crunchify-link crunchify-facebook" href="'.$facebookURL.'" target="_blank">Facebook</a>';
$variable .= '<a class="crunchify-link crunchify-googleplus" href="'.$googleURL.'" target="_blank">Google+</a>';
$variable .= '<a class="crunchify-link crunchify-buffer" href="'.$bufferURL.'" target="_blank">Buffer</a>';
$variable .= '<a class="crunchify-link crunchify-linkedin" href="'.$linkedInURL.'" target="_blank">LinkedIn</a>';
$variable .= '<a class="crunchify-link crunchify-pinterest" href="'.$pinterestURL.'" data-pin-custom="true" target="_blank">Pin It</a>';
$variable .= '</div>';
return $variable.$content;
}else{
// if not a post/page then don't include sharing button
return $variable.$content;
}
};
add_filter( 'the_content', 'crunchify_social_sharing_buttons');
Here is my category.php, as requested
<?php
/**
* The Category template file.
*
*
* @link
*
* @package Zeal
*/
get_header(); ?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="container archive-page">
<div class="row">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title"><h1><?php single_cat_title(); ?></h1>
</header><!-- .page-header -->
<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
<hr class="wp-block-separator">
<div id="category-menu"><a class="category-link" href="/">All</a> <a class="category-link" href="/">Education</a>
<a class="category-link" href="/">Industrial</a>
<a class="category-link" href="/">Leisure</a>
<a class="category-link" href="/">Medical</a>
<a class="category-link" href="/">Military</a>
<a class="category-link" href="/">Other</a>
<a class="category-link" href="/">Religious</a>
<a class="category-link" href="/">Residential</a>
</br>
<a class="category-link" href="/">
本文标签:
templatesIssues getting PHP to display in category pages
版权声明:本文标题:templates - Issues getting PHP to display in category pages 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1745038801a2638951.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论