我创建了一个帖子列表,每个帖子都是关于一个车型的。之后,我写了一篇关于最佳车型的帖子。这篇文章抓住了关于每一款车型的每一篇文章,并将它们以片段列表格式显示在主文章“最佳车型”中。
我正在使用下面的功能显示社交共享按钮。我想从显示社交按钮中排除当前帖子,以便按钮仅显示在帖子片段上。
例如获取当前帖子id并使用if语句对其进行过滤。谢谢
`功能crunchify\\u social\\u sharing\\u按钮($内容){
// 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 = \'https://twitter.com/intent/tweet?text=\'.$crunchifyTitle.\'&url=\'.$crunchifyURL.\'&via=dica.com.br\';
$facebookURL = \'https://www.facebook.com/sharer/sharer.php?u=\'.$crunchifyURL;
$whatsappURL = \'https://wa.me/?text=\'.$crunchifyTitle . \' \' . $crunchifyURL;
// Based on popular demand added Pinterest too
$pinterestURL = \'https://pinterest.com/pin/create/button/?url=\'.$crunchifyURL.\'&media=\'.$crunchifyThumbnail[0].\'&description=\'.$crunchifyTitle;
// Add sharing button at the end of page/page content
$content .= \'<ul class="ul">\';
$content .= \'<li class="twitter"> <a target="_blank" rel="noopener nofollow" href="\'. $twitterURL .\'" target="_blank"><svg class="icon text-btn-icon svg-inline--fa fa-w-18 fa-fw" style="fill: #fff; "><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-twitter"></use></svg> <span>Twitter </span></a>\';
$content .= \'<li class="facebook"> <a target="_blank" rel="noopener nofollow" href="\'.$facebookURL.\'" target="_blank"><svg class="icon text-btn-icon svg-inline--fa fa-w-18 fa-fw" style="fill: #fff; "><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-facebook-share"></use></svg> <span>Facebook </span></a>\';
$content .= \'<li id="hidewhatsapp" class="whatsapp"> <a href="\'.$whatsappURL.\'" target="_blank"><svg class="icon text-btn-icon svg-inline--fa fa-w-18 fa-fw" style="fill: #fff; viewBox="0 0 100 100" class="share-icon"> <use xlink:href="#icon-whatsapp"></use></svg> <span> WhatsApp </span></a>\';
$content .= \'</ul> </div>\';
return $content;
}
add_shortcode( \'share-buttons\', \'crunchify_social_sharing_buttons\' );`