💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 制作模板时经常用到的方法说明 ## 1,CMF美化URL cmf_url(); 在模板中这样使用: 栏目列表: `<a href="{:cmf_url('portal/List/index', ['id' =>57])}" target="_blank">查看更多</a> ` 文章详情: `<a href="{:url('portal/Article/index',array('id'=>$vo.id,'cid'=>$vo.category_id))}">` ## 2,获取图片地址 在模板中这样使用: `<img src="{:cmf_get_image_url($vo.more.thumbnail)}"> ` 或者使用管道符: `<img src="{$vo.image|cmf_get_image_url}">` 图片不存在时候,给个默认图片 <a href="{:url('portal/Article/index',array('id'=>$vo.id,'cid'=>$vo.category_id))}"> <empty name="vo.more.thumbnail"> <img src="__TMPL__/public/assets/images/default-thumbnail.png"> <else/> <img src="{:cmf_get_image_url($vo.more.thumbnail)}"> </empty> <h4><span>{$vo.post_title}</span></h4> </a> ## 3,模板中格式化时间 ``` {$vo.published_time|date='Y-m-d'} ``` ## 4,模板中使用自定义PHP函数 模板自定义函数位置: > \themes\模板名称\public\function.html ``` <php> /*可以加多个方法哟!*/ if (!function_exists('_sp_helloworld')) { function _sp_helloworld(){ echo "hello ThinkCMF!"; } } </php> ``` 在模板中这样调用函数: ``` {:_sp_helloworld()} 或者这样: <php> _sp_helloworld() </php> ``` ## 文章标签及选项说明 ``` <portal:articles item="vo" where="$where" order="post.create_time DESC" page="$page" categoryIds="$category.id" returnVarName="articles_data" relation="categories,user'"> .. HTML .. </portal:articles> ``` #### where | 查询条件变量, 支持数组和字符串,如$where #### limit | 最多查出文章数,如果分页开启,此设置无效 #### order | 文章排序方式 page|分页参数,如果设置分页参数会自动分页 #### relation | 关联查询,支持categories和user,多个以英文逗号分隔 **[ relation目前只能获取分类和用户(文章属于哪个分类哪个作者) ]** #### pageVarName | 分页后生成的分页变量名,只有设置分页参数时才有效 #### categoryIds | 分类 id,支持数组和字符串(英文逗号分开) ***** ## 获取指定栏目下的子栏目(二级分类) <php>$categoryId=1;</php> <portal:subCategories categoryId="$categoryId" item="vo"> {$vo.name}<br> {$vo.description}<br> </portal:subCategories> ## 获取所有分类(二、三级分类) <php>$categoryId=1;</php> <portal:allSubCategories categoryId="$categoryId" item="vo"> <a href="{:cmf_url('portal/List/index',array('id'=>$vo['id']))}">{$vo.name}</a><br> {$vo.description}<br> </portal:allSubCategories> ## 获取指定的子导航 <php> $parent_nav_menu_id=6; </php> <subNavigation parent="$parent_nav_menu_id" root="ul" id="main-navigation" class="nav navbar-nav navbar-nav-custom"> <subNavigationMenu root="li" class="menu-item"> <a href="{$menu.href|default=''}" target="{$menu.target|default=''}">{$menu.name|default=''}</a> </subNavigationMenu> <subNavigationFolder root="li" class="dropdown dropdown-custom" dropdown="ul" dropdown-class="dropdown-menu"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> {$menu.name|default=''}<span class="caret"></span> </a> </subNavigationFolder> </subNavigation> ## 获取所有的导航 <!--后台导航 id 为1--> <navigation nav-id="1" root="ul" id="main-navigation" class="nav navbar-nav navbar-nav-custom"> <navigationMenu root="li" class="menu-item menu-item-level-{$level}"> <a href="{$menu.href|default=''}" target="{$menu.target|default=''}">{$menu.name|default=''}</a> </navigationMenu> <navigationFolder root="li" class="dropdown dropdown-custom dropdown-custom-level-{$level}" dropdown="ul" dropdown-class="dropdown-menu dropdown-menu-level-{$level}"> <a href="#" class="dropdown-toggle dropdown-toggle-{$level}" data-toggle="dropdown"> {$menu.name|default=''}<span class="caret"></span> </a> </navigationFolder> </navigation> ## 文章搜索表单 <form method="post" action="{:cmf_url('portal/Search/index')}"> <input type="text" class="sous_k_f_text" name="keyword" placeholder="请输入关键词进行搜索" value="{:input('param.keyword','')}"> <button type="submit" class="sous_k_f_btn" value=""></button> </form> ## 调用配置文件变量QQ示例 ``` <a href="http://wpa.qq.com/msgrd?v=3&amp;uin={$theme_vars.last_qq}&amp;site=qq&amp;menu=yes" title="立即咨询">立即咨询</a> ``` ## 友情链接 <links> <a href="{$vo.url|default=''}" target="{$vo.target|default=''}">{$vo.name|default=''}</a> </links> ## 导航代码(bootstrap) <!--导航S--> <section class="daohl"> <nav class="daoh navbar navbar-default navbar-mobile bootsnav" role="navigation"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-menu"> <i class="glyphicon glyphicon-th-list"></i> </button> <a class="navbar-brand" href="__ROOT__"><img class="sg_logo" src="{$theme_vars.logo|cmf_get_image_url}" alt=""></a> </div> <div class="collapse navbar-collapse" id="navbar-menu"> <navigation nav-id="1" id="menu" root="ul" class="nav navbar-nav"> <navigationMenu root="li" class='active{$level}'> <a href="{$menu.href|default=''}" target="{$menu.target|default=''}">{$menu.name|default=''}</a> </navigationMenu> <navigationFolder root="li" class="dropdown" dropdown="ul" dropdown-class="dropdown-menu"> <a href="{$menu.href|default=''}"data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"> {$menu.name|default=''}<span class="caret"></span> </a> </navigationFolder> </navigation> </div> </div> </nav> </section> <!--导航E--> ## 幻灯片代码 (swiper插件) <!--幻灯片S--> <div class="swiper-container swiper-container1"> <php> $top_slide_id=empty($theme_vars['top_slide'])?1:$theme_vars['top_slide']; </php> <div class="swiper-wrapper"> <slides id="$top_slide_id"> <div class="swiper-slide" style="background-image: url({$vo.image|cmf_get_image_url});"><a href="{$vo.url|default=''}"></a></div> </slides> </div> <div class="swiper-pagination"></div> <div class="swiper-button-next"></div> <div class="swiper-button-prev"></div> </div> <!--幻灯片E--> ## 底部导航栏(根据导航ID来自定义导航菜单) <navigation nav-id="1" root="ul" class="clearfix" max-level="0"> <navigationMenu root="li"> <a href="{$menu.href|default=''}" target="{$menu.target|default=''}">{$menu.name|default=''}</a> </navigationMenu> </navigation> ## 判断会员是否登录 <php>$user=cmf_get_current_user(); </php> <if condition="empty($user['id'])"> <div class="daohl_hy"> <a href="{:cmf_url('user/Login/index')}">会员登录</a> </div> <else/> <div class="daohl_hy"> 您好,<a href="{:cmf_url('user/Profile/center')}" title="进入会员中心">{$user.user_login?$user.user_login:($user.mobile?$user.mobile:$user.user_email)}</a> <a href="{:cmf_url('user/Index/logout')}" title="退出登录"><i class="fa fa-sign-out"></i> &nbsp;退出</a> </div> </if> ## 反馈信息表单(先安装留言的插件,某些页面上用不上的字段用hidden) <form action="{:cmf_plugin_url('Msg://Do/addmsg');}" method="post" name="myform" class="clearfix" novalidate="novalidate"> <input type="text" name="name" placeholder="请输入您的姓名"> <input type="text" name="phone" placeholder="请输入您的电话"> <input type="text" name="email" placeholder="请输入您的邮箱"> <input type="hidden" name="msg" value="反馈信息"> <button type="submit" name="submit">立即预约</button> </form>