如何在首页和发现中插入自定义文章

jat
jat 这家伙很懒,还没有设置简介

8 人点赞了该文章 · 5350 浏览

首先,你要自己发表一篇文章,记下它的 id,比如这篇文章的 id 就是 134。 然后,在 app/home/main.php(首页)第 64 - 67 行 {{{ if (! $this->user_info['email']) { HTTP::redirect('/account/complete_profile/'); } }}} 或 app/explore/main.php(发现)第 47 - 57 行 {{{ if ($_GET['category']) { if (is_numeric($_GET['category'])) { $category_info = $this->model('system')->get_category_info($_GET['category']); } else { $category_info = $this->model('system')->get_category_info_by_url_token($_GET['category']); } } }}} 之后加入 {{{ $article_showed_id = 刚才记下的文章 id; $article_showed_info = $this->model('article')->get_article_info_by_id($article_showed_id); if ($article_showed_info['has_attach']) { $article_showed_info['attachs'] = $this->model('publish')->get_attach('article', $article_showed_info['id'], 'min'); $article_showed_info['attachs_ids'] = FORMAT::parse_attachs($article_showed_info['message'], true); } $article_showed_info['message'] = FORMAT::parse_attachs(nl2br(FORMAT::parse_markdown($article_showed_info['message']))); TPL::assign('article_showed_info', $article_showed_info); }}} $article_showed_info 是一个多维数组,可以在模板文件(views/default/home/index.tpl.htm 或 views/default/explore/index.tpl.htm)中使用 $this->article_showed_info 引用。 下面介绍下该数组的键: {{{ $this->article_showed_info['id'] 文章 id $this->article_showed_info['uid'] 发表这篇文章的用户 id $this->article_showed_info['title'] 文章标题(如果过长则为部分) $this->article_showed_info['message'] 文章内容 $this->article_showed_info['comments'] 文章的评论数 $this->article_showed_info['views'] 文章的浏览数 $this->article_showed_info['add_time'] 文章的添加时间(UNIX 时间) $this->article_showed_info['has_attach'] 是否有附件 $this->article_showed_info['lock'] 是否锁定 $this->article_showed_info['votes'] 被赞数 $this->article_showed_info['title_fulltext'] 文章标题(全部) $this->article_showed_info['category_id'] 文章所属话题的 id $this->article_showed_info['is_recommend'] 是否被推荐 $this->article_showed_info['attachs'] 文章的附件(关联数组,键为附件的 id,值为关联数组,请使用 foreach 遍历) $this->article_showed_info['attachs_ids'] 插入到文章的附件(数值数组,值为附件的 id) }}} 遍历 $this->article_info['attachs']: {{{ foreach ($this->article_info['attachs'] as $attach) { } }}} 下面介绍下 $attach 的键: {{{ $attach['id'] = 附件 id $attach['is_image'] 附件是否是图片 $attach['file_name'] 附件上传时的文件名 $attach['access_key'] 附件的访问密钥(暂时没用) $attach['attachment'] 附件的 url $attach['thumb'] 附件为图像时的缩略图 url(非图像时无此键) }}} 输出附件下载链接时,应该使用 download_url($attach['file_name'], $attach['attachment']),而不应该直接使用 $attach['attachment']),直接使用会导致文件名不正确。 如果想输出文章的更多内容可以参考 app/article/main.php,具体示例请看 views/default/article/index.tpl.htm。

发布于 2014-05-11 15:16

免责声明:

本文由 jat 原创发布于 WeCenter ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

seosns
2014-10-12 11:15
http://www.index5.net 首页缩略图有教程的,可以直接下载覆盖
abcalmas
2014-10-11 23:15
我读了半天都没明白啊。。。 我关心首页当中问题的或者答案的缩略图怎么调用,可以举个例子吗?
abcalmas
2014-10-11 23:09
如何导入缩略图? 知道写个文章好吗。首页展现的内容怎样调用答案里的或者问题里的缩略图
seosns
2014-10-11 22:09
有什么不明白?
abcalmas
2014-10-11 00:57
我也到现在还没琢磨清楚这个。。。这个可以有
seosns
2014-05-12 21:17
如何自动调用问答或者文章的缩略图呢?
accouter
2014-05-11 16:36
呵呵,因为用程序的人大多数都是代码不太懂的,所以都在模板层面做文章。其实根据你们目前将文章统一到发现列表的做法,强烈建议直接在代码层面将文章的摘要和缩略图调用写进去,然后你们的文章功能就可以像wordpress的文章列表那样灵活使用了,比如在发现列表里面显示文章列表的时候就把摘要和缩略图也显示出来,和问题区分开来。
170号码资讯网
2014-05-11 16:33
支持,需要这类的文章
jat
2014-05-11 16:31
不要在前端截啊……
accouter
2014-05-11 16:03
谢谢!图片缩略图可以调很重要,文章摘要只要能够截取就可以,截取的函数应该能够去除截取部分内容的markdown格式标记吧?像现在的方式是通过css隐藏的方式截取就很不好,不能够控制摘要和缩略图的排列格式