PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通

QQ:420220301 微信/手机:150-3210-7690
当前位置:首页 > CMS教程 > ThinkCMF

门户文章列表页模板

管理员 2024-12-15
ThinkCMF
124

文章列表页主要是给某个分类显示文章列表用的。
当前页可用的变量有$category,这个变量是一个模型对象,表示当前分类,取值时可以直接把它当成数组用。

输出$category内部的值

{$category.id} <!--输出分类 id-->{$category.parent_id} <!--输出分类父级分类 id-->{$category.name} <!--输出分类名称-->{$category.description} <!--输出分类描述-->{$category.seo_title} <!--输出分类seo标题-->{$category.seo_keywords} <!--输出分类 seo 关键字-->{$category.seo_description} <!--输出分类 seo 描述-->

以上的值也可以当成 php 变量直接输出,这里只演示一下怎么输出 id 属性

<php>echo $category['id']; /*输出分类 id*/</php>

显示分类缩略图

文章分类缩略图是保存分类的 more 字段中

<!--先判断缩略图是否设置了--><notempty name="category.more.thumbnail">
	<img src="{:cmf_get_image_url($category.more.thumbnail)}"/></notempty>

cmf_get_image_url方法是用来把缩略图的相对路径转化为可访问 url 的。

当前分类的文章列表制作

<php>
    $where=[
    'post.create_time'=>['egt',0]
    ];</php><portal:articles item="vo" where="$where" order="post.create_time DESC" page="10"
                 relation="categories"
                 categoryIds="$category.id"
                 returnVarName="articles_data">
    <div class="list-boxes">
        <h2><a href="{:cmf_url('portal/Article/index',array('id'=>$vo['id'],'cid'=>$category['id']))}">{$vo.post_title}</a>
        </h2>
        <p>{$vo.post_excerpt}</p>
        <div>
            <div class="pull-left">
                <div class="list-actions">
                    <a href="javascript:;"><i class="fa fa-eye"></i><span>{$vo.post_hits}</span></a>
                    <a href="{:url('portal/Article/doLike',array('id'=>$vo['id']))}"
                       class="js-count-btn"><i class="fa fa-thumbs-up"></i><span class="count">{$vo.post_like}</span></a>
                    <a href="{:url('user/Favorite/add',array('id'=>$vo['id'],'cid'=>$category['id']))}"
                       class="js-favorite-btn"
                       data-id="{$vo.id}"
                       data-table="portal_post"
                       data-title="{:base64_encode($vo.post_title)}"
                       data-url="{:cmf_url_encode('portal/Article/index',array('id'=>$vo['id'],'cid'=>$category['id']))}"
                    >
                        <i class="fa fa-star-o"></i>
                    </a>
                </div>
            </div>
            <a class="btn btn-warning btn-sm pull-right"
               href="{:cmf_url('portal/Article/index',array('id'=>$vo['id'],'cid'=>$category['id']))}">查看更多</a>
        </div>
    </div></portal:articles><ul class="pagination">
    <page/></ul>

制作当前分类SEO

<head>
    <title>{$category.name} {$category.seo_title} {$site_info.site_name|default=''}</title>
    <meta name="keywords" content="{$category.seo_keywords},{$site_info.site_seo_keywords|default=''}"/>
    <meta name="description" content="{$category.seo_description},{$site_info.site_seo_description|default=''}">
    <!--省略...--></head>

制作当前分类的面包屑

<ol class="breadcrumb">
  <li><a href="__ROOT__/">首页</a></li>
  <portal:breadcrumb cid="category.id" self="false">
	<li><a href="{:url('portal/List/index',['id'=>$vo['id']])}">{$vo.name}</a></li>
  </portal:breadcrumb>
  <li class="active">{$category.name}</li></ol>

创建文章列表模板

public/themes/quick_start/portal目录下创建list.html文件,内容如下:

<!DOCTYPE html><html><head>
    <title>{$category.name} {$category.seo_title} {$site_info.site_name|default=''}</title>
    <meta name="keywords" content="{$category.seo_keywords},{$site_info.site_seo_keywords|default=''}"/>
    <meta name="description" content="{$category.seo_description},{$site_info.site_seo_description|default=''}">
    <include file="public@head"/></head><body class="body-white"><include file="public@nav"/><div class="container">
    <h2>{$category.name}</h2>
    <div class="row">
        <div class="col-md-9">
            <div class="">
                <php>
                    $where=[
                    'post.create_time'=>['egt',0]
                    ];
                </php>
                <portal:articles item="vo" where="$where" order="post.create_time DESC" page="10"
                                 relation="categories"
                                 categoryIds="$category.id"
                                 returnVarName="articles_data">
                    <div class="list-boxes">
                        <h2><a href="{:cmf_url('portal/Article/index',array('id'=>$vo['id'],'cid'=>$category['id']))}">{$vo.post_title}</a>
                        </h2>
                        <p>{$vo.post_excerpt}</p>
                        <div>
                            <div class="pull-left">
                                <div class="list-actions">
                                    <a href="javascript:;"><i class="fa fa-eye"></i><span>{$vo.post_hits}</span></a>
                                    <a href="{:url('portal/Article/doLike',array('id'=>$vo['id']))}"
                                       class="js-count-btn"><i class="fa fa-thumbs-up"></i><span class="count">{$vo.post_like}</span></a>
                                    <a href="{:url('user/Favorite/add',array('id'=>$vo['id'],'cid'=>$category['id']))}"
                                       class="js-favorite-btn"
                                       data-id="{$vo.id}"
                                       data-table="portal_post"
                                       data-title="{:base64_encode($vo.post_title)}"
                                       data-url="{:cmf_url_encode('portal/Article/index',array('id'=>$vo['id'],'cid'=>$category['id']))}"
                                    >
                                        <i class="fa fa-star-o"></i>
                                    </a>
                                </div>
                            </div>
                            <a class="btn btn-warning btn-sm pull-right"
                               href="{:cmf_url('portal/Article/index',array('id'=>$vo['id'],'cid'=>$category['id']))}">查看更多</a>
                        </div>
                    </div>
                </portal:articles>

            </div>
            <ul class="pagination">
                <page/>
            </ul>
        </div>
        <div class="col-md-3">


        </div>
    </div></div><include file="public@footer"/><include file="public@scripts"/></body></html>

添加模板配置文件

public/themes/quick_start/portal目录下创建list.json文件,内容如下:

{
    "name": "文章列表页",
    "action": "portal/List/index",
    "description": "文章列表模板文件",
    "order": 10.0,
    "more": {
        "vars": {
        },
        "widgets": {
        }
    }}

更新模板

至此门户文章列表模板制作完成。



希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部