给typecho添加个打赏功能

chen'mo
2021-03-01 / 0 评论 / 3,438 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年03月01日,已超过1152天没有更新,若内容或图片失效,请留言反馈。

虽然没有人给我打赏,但这功能必须要有!
功能虽然没用,但看着比较爽!

参考两篇文章:
https://www.ijkxs.com/archives/15.html
https://xiamp.net/archives/new-topic-reward-button.html

一、如果你没有买插件,那以下内容基本没用。

我拿过来是学习它的方法。

添加打赏按扭。

<?php if (isPluginEnabled('TePass')) : ?>
    <a class="btn btn-warning" onclick="show_reward()" href="javascript:void(0);"><?php _e("打赏"); ?></a>
<?php endif; ?>

isPluginEnabled是检测插件是否激活的方法,具体如下

function isPluginEnabled($pluginName)
{
    return array_key_exists($pluginName, Typecho_Plugin::export()['activated']);
}

然后把调用打赏区域的代码包裹起来(主要是为了限定css生效范围)

<?php if (isPluginEnabled('TePass')) : ?>
    <div class="entry-support">
        <?php echo TePass_Plugin::getReward(); ?>
    </div>
    <?php endif; ?>

接着增加CSS样式

.btn_reward { /*隐藏TePass输出的按钮*/
  display: none;
}
.entry-support .p-list {
  padding: 10px 0;
  margin: 0 -5px;
  /* display: none 这是捐赠用户列表,无需要就隐藏 */
}
.entry-support .p-list .clusr {
  /* 限制头像大小 */
  width: 45px;
  height: 45px;
  margin: 5px;
}

然后你就可以点击打赏按钮显示打赏区域了。

二、结合自己买的TePass插件,和JOE主题,折腾一上午,也基本上弄好了。

我发现原理是在点击按扭 添加 onclick="show_reward()"效果,然后加个自动隐藏和显示效果。

我的JQ代码比较简单:

$('.pay-author').click(function(){
      $(".tepasspost").toggle();
})
</script>

具体在/WEB/usr/plugins/TePass/theme/reward/need_your_reward.php里可看到打赏的实现效果
在想要打赏的位置添加:

 <?php $all = Typecho_Plugin::export();?>
 <?php if (array_key_exists('TePass', $all['activated'])) : ?>
 <?php echo TePass_Plugin::getTePass(); ?>
 <?php echo TePass_Plugin::getReward(); ?>
 <?php endif; ?>
一键分享到QQ空间、QQ好友、新浪微博、微信代码
« 上一篇 03-01
Album for typecho 相册插件 本地上传修复版
下一篇 » 03-02

评论 (0)

插入图片