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

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

给文章列表页添加多模板

管理员 2024-12-15
ThinkCMF
92

文章列表默认模板是list.html,本节我们讲一下如何给它增加多个模板文件。

创建模板文件list2.html

public/themes/quick_start/portal目录下创建list2.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>
    <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>
    <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>

以上内容你可以根据自己的需求自己更改。

创建模板配置文件list2.json

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

{
    "name": "文章列表页2",
    "action": "portal/List/index",
    "description": "文章列表模板文件2,瀑布流模板",
    "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交谈

回顶部