dedecms 微信分享链接和图文
时间 : 2024-01-07 17:30:02 声明: : 文章内容来自网络,不保证准确性,请自行甄别信息有效性
最佳答案
在DedeCMS网站中添加微信分享链接和图文功能可以增强网站的社交化推广效果,方便用户进行文章的分享和传播。下面是添加微信分享链接和图文的步骤:
1. 登录DedeCMS后台管理系统,进入“模块管理”页面。
2. 找到并点击“模块设计”选项卡,在对应的模块中添加微信分享按钮。
3. 在模块设计中找到需要添加分享按钮的位置,如文章详情页的底部。
4. 在该位置插入以下代码,以实现微信分享链接和图文功能:
<?php
require_once(dirname(__FILE__).'/../include/common.inc.php');
$wx_share_images = '文章缩略图URL';
$wx_share_title = '文章标题';
$wx_share_desc = '文章简介';
$wx_share_url = $cfg_basehost.$_SERVER['REQUEST_URI'];
$wx_share_title = str_replace('"', '', $wx_share_title);
$wx_share_title = str_replace("'", '', $wx_share_title);
$wx_share_title = strip_tags($wx_share_title);
$wx_share_desc = str_replace('"', '', $wx_share_desc);
$wx_share_desc = str_replace("'", '', $wx_share_desc);
$wx_share_desc = strip_tags($wx_share_desc);
$wx_share_images = str_replace('"', '', $wx_share_images);
$wx_share_images = str_replace("'", '', $wx_share_images);
$wx_share_images = strip_tags($wx_share_images);
$wx_share_images = !empty($wx_share_images) ? $wx_share_images : '/images/share_default.png';
?>
<div id="wx_share" style="display:none;">
<h1><?php echo $wx_share_title;?></h1>
<p><?php echo $wx_share_desc;?>
<p><img src="<?php echo $wx_share_images;?>" alt="">
<p>查看更多:<a href="<?php echo $wx_share_url;?>"><?php echo $wx_share_title;?></a>
</div>
<script>
wx.config({
//根据自己的实际情况填写以下参数
appId: '公众号AppId', // 必填,公众号的唯一标识
timestamp: 1561464390, // 必填,生成签名的时间戳
nonceStr: '马上注册', // 必填,生成签名的随机串
signature: 'bfaef8c50f02572e715b2c37be904aad16bc045f',// 必填,签名
jsApiList: [
'onMenuShareAppMessage',
'onMenuShareTimeline',
'onMenuShareQQ',
'onMenuShareWeibo',
'updateAppMessageShareData',
'updateTimelineShareData'
]
});
wx.ready(function() {
var wx_share_config = {
title: '<?php echo $wx_share_title;?>', // 分享标题
desc: '<?php echo $wx_share_desc;?>', // 分享描述
link: window.location.href, // 分享链接
imgUrl: '<?php echo $wx_share_images;?>', // 分享图标
type: 'link', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {},
cancel: function () {}
};
wx.updateAppMessageShareData(wx_share_config);
wx.updateTimelineShareData(wx_share_config);
wx.onMenuShareAppMessage(wx_share_config);
wx.onMenuShareTimeline(wx_share_config);
wx.onMenuShareQQ(wx_share_config);
wx.onMenuShareWeibo(wx_share_config);
// 通过js-api改变分享的标题和描述
wx.updateAppMessageShareData({
title: '<?php echo $wx_share_title;?>',
desc: '<?php echo $wx_share_desc;?>',
link: window.location.href,
imgUrl: '<?php echo $wx_share_images;?>'
});
wx.updateTimelineShareData({
title: '<?php echo $wx_share_title;?>',
link: window.location.href,
imgUrl: '<?php echo $wx_share_images;?>'
});
});
</script>
5. 替换代码中的相关参数,包括文章缩略图URL($wx_share_images)、文章标题($wx_share_title)、文章简介($wx_share_desc)和公众号AppId。根据自己的实际情况进行修改。
6. 保存代码并更新模板缓存。
7. 刷新文章详情页,在底部就可以看到添加的微信分享链接和图文效果。
通过以上步骤,就可以在DedeCMS网站中添加微信分享链接和图文功能了,让用户方便地进行文章的分享和传播,提升网站的社交化推广效果。
其他答案
DedeCMS 微信分享链接和图文的实现方法如下:
首先,需要确保你的网站已经安装了微信分享接口插件。接下来,你需要在你的网站上的需要分享的页面上添加微信分享链接和图文的相关代码。
1. 添加微信分享链接的代码:
在需要分享的页面的头部,添加以下代码:
在以上代码中,你需要将以下变量替换为你自己的信息:
- appId: 你的微信公众号 AppId;
- timestamp: 生成的时间戳;
- nonceStr: 生成的随机字符串;
- signature: 签名;
- imgUrl: 分享图标的 URL。
2. 添加微信图文分享的代码:
在需要分享的页面的头部,添加以下代码:
同样,你需要将以上代码中的相关信息替换为你自己的内容。
完成以上步骤后,保存并上传你的网站文件,刷新浏览器,即可在页面上看到微信分享链接和图文的效果。记得在替换图片链接时,确保图片链接是可访问的。
上一篇
discuz导航 不能写主页
下一篇
dedecms自定义字段php
https/SSL证书广告优选IDC>>
推荐主题模板更多>>
推荐文章







