# Typecho如何实现主题前台实现删除文章功能

*Published:* 2024-01-01
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2024年1月1日，已超过 180天没有更新



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

```
<?php <a class="tag_link" href="https://www.xarjtc.com/tag/typecho" target="_blank" title="查看Typecho此标签更多文章"><abbr title="">Typecho</abbr></a>_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>
```