您现在的位置是:首页 > cms教程 > discuz教程discuz教程

discuz常用函数调用方法示例

盼山2025-06-28 17:09:06discuz教程已有2人查阅

导读调用主题的查看次数discuz帖子正文下方有一组自动推荐的相关帖子,其调用代码为调用会员头像!代码有三种格式:内容页TAG代码$post[tags]

调用主题的查看次数
{lang show}:$_G[forum_thread][views]
discuz帖子正文下方有一组自动推荐的相关帖子,其调用代码为
<!--相关教程推荐-->
<!--{if $post['relateitem']}-->
<div class="mtw mbw">
<h3 class="pbm mbm bbda">{lang related_thread}</h3>
<ul class="xl xl2 cl">
<!--{loop $post['relateitem'] $var}-->
<li>? <a href="forum<font color="#000000"><span style="line-height: normal; background-color: rgb(255, 102, 255);">.</span></font>php?mod=viewthread&tid=$var[tid]" title="$var[subject]" target="_blank">$var[subject]</a></li>
<!--{/loop}-->
</ul>
</div>
<!--{/if}-->
<!--相关教程推荐-->
调用会员头像!代码有三种格式:
<!--{avatar($_G[uid],small)}--> //调用小头像 默认长度48px 宽度48px
<!--{avatar($_G[uid],middle)}--> //调用中头像 默认长度120px 宽度120px
<!--{avatar($_G[uid],big)}--> //调用大头像 默认长度200px 宽度200px
内容页TAG代码$post[tags]
<!--{if $post['first'] && ($post[tags] || $relatedkeywords) && $_GET['from'] != 'preview'}-->
<div class="ptg mbm mtn">
<!--{if $post[tags]}-->
<!--{eval $tagi = 0;}-->
<!--{loop $post[tags] $var}-->
<!--{if $tagi}-->, <!--{/if}--><a title="$var[1]" href="misc.php?mod=tag&id=$var[0]" target="_blank">$var[1]</a>
<!--{eval $tagi++;}-->
<!--{/loop}-->
<!--{/if}-->
<!--{if $relatedkeywords}--><span>$relatedkeywords</span><!--{/if}-->
</div>
<!--{/if}-->
Discuz登录名称变量弹窗登录
<a href="member.php?mod=logging&action=login" onclick="showWindow('login', this.href)">{lang login}</a>
以上链接在Discuz中点击会直接弹出登录框!
{lang login}为登录文字变量
替换搜索框默认文字:
{lang enter_content}是模板字段,所代替的文字是:“请输入搜索内容”。
就是我们搜索框中的默认文字
打开网站根目录,进入以下文件夹内/source/language
找到:lang_template.php
enter_conten
默认调用会员信息的代码!
<!--{template common/header_userstatus}-->
默认调用会员信息的代码!
内容页标题调用代码
<h1 class="ph">$article[title] <!--{if $article['status'] == 1}-->({lang moderate_need})<!--{elseif $article['status'] == 2}-->({lang ignored})<!--{/if}--></h1>
上面的代码是Discuz内容页标题调用代码
discuz文章的上一篇和下一篇
discuz文章的上一篇和下一篇
$article['preaid'] || $article['nextaid']
<!--{if $article['preaid'] || $article['nextaid']}-->
<div class="pren pbm cl">
<!--{if $article['prearticle']}--><em>{lang pre_article}<a href="{$article['prearticle']['url']}">{$article['prearticle']['title']}</a></em><!--{/if}-->
<!--{if $article['nextarticle']}--><em>{lang next_article}<a href="{$article['nextarticle']['url']}">{$article['nextarticle']['title']}</a></em><!--{/if}-->
</div>
<!--{/if}-->
先判断文章是否有上一篇或者下一篇存在,只要其中一个条件成立,那么就执行里面的内容
<!--{if $article['preaid'] || $article['nextaid']}-->
然后执行里面的时候再来做判断
<div class="pren pbm cl">
<!--{if $article['prearticle']}-->
有上一篇就显示上一篇的连接和名称
论坛信息统计代码分析
论坛信息统计代码主要包含
今日贴子数 | 昨日帖子数 | 帖子数 | 会员 | 新会员
模板中展现的方式:
今日: 0|昨日: 0|帖子: 2|会员: 1|欢迎新会员: admin
<!--{if empty($gid)}-->
<div id="chart" class="bm bw0 cl">
<p class="chart z">{lang index_today}: <em>$todayposts</em><span class="pipe">|</span>{lang index_yesterday}: <em>$postdata[0]</em><span class="pipe">|</span>{lang index_posts}: <em>$posts</em><span class="pipe">|</span>{lang index_members}: <em>$_G['cache']['userstats']['totalmembers']</em><!--{if $_G['cache']['userstats']['newsetuser']}--><span class="pipe">|</span>{lang welcome_new_members}: <em><a href="home.php?mod=space&username={echo rawurlencode($_G['cache']['userstats']['newsetuser'])}" target="_blank" class="xi2">$_G['cache']['userstats']['newsetuser']</a></em><!--{/if}--></p>
<div class="y">
<!--{hook/index_nav_extra}-->
<!--{if $_G['uid']}--><a href="forum.php?mod=guide&view=my" title="{lang my_posts}" class="xi2">{lang my_posts}</a><!--{/if}--><!--{if !empty($_G['setting']['search']['forum']['status'])}--><!--{if $_G['uid']}--><span class="pipe">|</span><!--{/if}--><a href="forum.php?mod=guide&view=new" title="{lang show_newthreads}" class="xi2">{lang show_newthreads}</a><!--{/if}-->
</div>
</div>
<!--{/if}-->
论坛板块简介调用代码
<!--{if $forum[description]}--><p class="xg2">$forum[description]</p><!--{/if}-->
在默认情况下是只有一横排显示一个板块的时候才显示,所以这里你就可以把他单独提出来,加到多板块横排的代码里面!
文章列表页图片
<!--{if $value[pic]}-->
<!--{if $value[pic]}--><div class="atc"><a href="$article_url" target="_blank"><img src="$value[pic]" alt="$value[title]" class="tn" /></a></div><!--{/if}-->
这段代码的意思
如果内容中存在封面图片,则显示
<div class="atc"><a href="$article_url" target="_blank"><img src="$value[pic]" alt="$value[title]" class="tn" /></a></div>
$article_url 这个是文章的网址
$value[pic] 这个是图片路径
$value[title] 文章标题
$thread[dateline]帖子列表页作者发布时间
<em><span{if $thread['istoday']} class="xi1"{/if}>$thread[dateline]</span></em>
$value[viewnum]和$value[commentnum]二次开发Discuz可以使用的方法
打开网站根目录/source/module/portal/portal_list.php搜
category_get_list
在里面加入以下代码:添加一下代码
$article_count = C::t('portal_article_count')->fetch($value['aid']);
if($article_count) $value = array_merge($article_count, $value);
添加前是这样:
添加后是这样:
添加以就可以在模板模板里面使用
$value[commentnum] //<span style="line-height: 1.5; background-color: rgb(255, 255, 255);">调用评论数</span>
$value[viewnum] //<span style="line-height: 1.5; background-color: rgb(255, 255, 255);">调用浏览</span>

本文标签:

很赞哦! (0)

暂无内容
暂无内容
暂无内容
暂无内容
留言与评论 (共有 0 条评论)
昵称:
匿名发表 登录账号
         
验证码: