在php中,我有一个使用atts的短码变量,我不知道如何在 "title "和 "url "的短码中管理这个变量中的'和'。
$ret = '<a href="http://twitter.com/intent/tweet?text=[slshar text="title"]&url=[slshar text="url"]">Link</a>';
我不知道如何在 "标题 "和 "url "的短码中管理这个变量中的 "和"。我试了一下 \"title\" => 不见得有效
[slshar text="title"] = "Titre du post 2" = "Titre du post 2" [slshar text="url"] = "slug of post 2" '= "https;/pur-plan.compost2" 结果必须是 。 $ret = '<a href="http://twitter.com/intent/tweet?text="Titre du post"&url="https;//pur-plan.com/post2">Link</a>;
我测试了shorcode:每件事情都是确定的,返回的值也是确定的。 使用这种语法,返回的URL在"?text="之后被截断。这是正常的,因为 "我希望我的解释足以让你帮助我。请你帮我解决这个问题。致敬,布鲁诺
谢谢你的回答。我用下面的方法解决了这个问题,并使用一些CSS来设计按钮。如果你自定义一个循环的档案(与Elementor自定义皮肤为例),这段代码显示链接分享到Twitter和Facebook的文章。
add_shortcode( 'social-sharing-inf', function ( $atts) {
extract(shortcode_atts(array(
'inf' => '',
), $atts));
global $post;
switch ( $inf ) {
case 'twitter' :
$ret = '<a href="http://twitter.com/intent/tweet?text=';
$ret .= 'PUR-PLAN.com vous propose la bonne affaire suivante :%0D' . $post->post_title .'%0DCliquez sur le lien suivant pour y accéder :';
$ret .= '&url=https://pur-plan.com/' . $post->post_name;
$ret .= '" onclick="window.open(this.href, \'twitterwindow\',\'left=20,top=20,width=600,height=300,toolbar=0,resizable=1\'); return false;" ';
$ret .= 'class="share-button-twitter-a"><i class="fa fa-twitter"></i>Twitter</a>';
break;
case 'facebook' :
$ret = '<a href="https://www.facebook.com/sharer.php?u=https://pur-plan.com/' . $post->post_name;
$ret .= '" onclick="window.open(this.href, \'facebookwindow\',\'left=20,top=20,width=600,height=700,toolbar=0,resizable=1\'); return false;" ';
$ret .= 'class="share-button-facebook-a"><i class="fa fa-facebook"></i>facebook </a>';
break;
}
wp_reset_postdata();
return "$ret";
});
我用短码调用。[social-sharing-inf inf="twitter"]和[social-sharing-inf inf="facebook"]当然,这段代码还可以优化,但效果不错。如果你有任何改进,我会接受它!