Typecho Wiki
每一个作品都值得被记录

Typecho前台发布文章功能的实现方法

Typecho维基君Typecho教程 • 1047次浏览 • 发布 2021-08-24 • 更新 2021-08-24
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码
🛜自用大流量超低月租手机卡推荐榜单 #拒绝流量焦虑

一直很喜欢Typecho博客程序的简洁小巧,用来做一句话博客或者生活博客最适合不过,而对于做一句话博客,实现typecho前台发布的功能就更强大了。博客吧搜索了下,有网友给出了相关教程。

操作步骤:

  • 在当前主题的header.php文件或者index.php文件添加以下代码,实现前台发布表单:
    <?php if($this->user->hasLogin()): //判断是否登录 ?>  
        <div class="post"> <!--按个人CSS的更改-->     
            <form action="<?php $this->options->siteUrl(); ?>action/contents-post-edit" method="post" name="write_post">     
                <input type="hidden" id="title" name="title" value="<?php echo date("Y-m-d H:i:s");?>" /><!--以发布时间作标题,把这里的hidden改成text就能自定义标题了-->     
                <p><textarea name="text" cols="100" rows="4" id="text" autocomplete="off" onkeydown='countChar("text","counter");' onkeyup='countChar("text","counter");'></textarea></p><!--输入框-->     
                <input type="hidden" id="allowComment" name="allowComment" value="1" checked="true" /><!--允许评论-->     
                <input type="hidden" name="do" value="publish" /><!--公开,可以无视-->               
                <input type="submit" class="pub" value="Send" />     
            </form>                          
        </div>     
    <?php endif; ?>
  • 文章类型的选择,在</form>前添加代码:
        <p>  
            <input type="radio" name="format" id="format-post" value="post" checked="checked">  
                <label for="format-post">微博</label>     
            <input type="radio" name="format" id="format-gallery" value="gallery">  
                <label for="format-gallery">图片</label>     
            <input type="radio" name="format" id="format-video" value="video">  
                <label for="format-video">视频</label>     
            <input type="radio" name="format" id="format-audio" value="audio">  
                <label for="format-audio">音乐</label>  
        </p>
  • 添加随机引导语,不需要可不添加:
    <?php 
        $h2 = array(   
                '随便说说',   
                '随时随地分享身边的新鲜事~',   
                '来,说说你在想什么,做什么',   
                '来搜狐微博看我',   
                '嘀咕一下'   
            );    
    ?>      
    <h2><?php echo $h2[(array_rand($h2))]; ?></h2>
  • 然后保存文件即可,输入表单的美化,自己通过添加CSS样式调整。

核心代码摘自:Ben’s Lab

广告声明:文内含有的对外跳转链接(包括不限于超链接、二维码、口令等形式),用于传递更多信息,节省甄选时间,结果仅供参考,Typecho.Wiki所有文章均包含本声明。
本文检索关键词:Typecho教程
厂商投放

【腾讯云】🎉五一云上盛惠!云服务器99元/月续费同价!

腾讯云五一劳动节海量产品 · 轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。快来腾讯云选购吧!

广告
添加新评论 »