首页 » 收集 » 正文内容
Typecho主题前台实现删除文章功能
寻梦xunm| 610| 收集
3年前
超过1105天 温馨提示
本文最后更新于2021年09月10日,已超过1105天没有更新,若内容或图片失效,请留言反馈。

将下面的代码放到 post.php 中即可

<?php Typecho_Widget::widget('Widget_Security')->to($security); ?>
<a href="<?php $security->index('/action/contents-post-edit?do=delete&cid='.$this->cid); ?>">删除文章</a>

点击按钮立即删除文章!

上面的代码虽然实现了功能,但却泯灭了人性!下面我们完善下人性部分,代码改为

<?php Typecho_Widget::widget('Widget_Security')->to($security); ?>
<a href="<?php $security->index('/action/contents-post-edit?do=delete&cid='.$this->cid); ?>" onclick="javascript:return p_del()">删除文章</a>
<script>
function p_del() {
    var msg = "您真的确定要删除吗?";
    if (confirm(msg)==true){
        return true;
    }else{
        return false;
    }
}
</script>

这样弄好,点击按钮会弹出确认框,问其是否删除文章,用户确认后才会删除,比较符合操作习惯!

post.php 页面成功删除文章后,因为文章不存在了,所以页面自动跳到了 404 页面

文章来源于:https://www.dpaoz.com/812

0 赞 or 打赏
喜欢就打赏一点
微信 支付宝
隐私
Q Q:1340326824
邮箱:vipshiyi@qq.com
QQ群:422720328

我的音乐