杰克工作室 发表于 2023-3-13 16:30

Discuz! 中实现不同版块使用不同的模板文件的方法

<p>通过此修改可在Discuz!X1后台为不同版块设置不同的模板文件。在需要为论坛不同版块设置不同模板风格的时候特别有用,比如你专门一个版块用来发布活动,那么可以为这个版块专门做一个模板文件,从而实现个性化的要求:</p>

<p>安装步骤</p>

<p>第一步:升级数据库</p>

<pre>
ALTER TABLE `pre_forum_forum` ADD `ffile` CHAR( 40 ) NOT NULL AFTER `styleid` , ADD `vfile` CHAR( 40 ) NOT NULL AFTER `ffile`;</pre>

<p>第二步:修改source/admincp/admincp_forums.php文件</p>

<p>找到以下代码</p>

<pre>
showsetting(&#39;forums_edit_extend_threadcache&#39;, &#39;threadcachesnew&#39;, $forum[&#39;threadcaches&#39;], &#39;text&#39;);</pre>

<p>在下面添加</p>

<p>//----edit</p>

<pre>
showsetting(&#39;forums_edit_extend_ffile&#39;, &#39;ffilenew&#39;, $forum[&#39;ffile&#39;], &#39;text&#39;);

showsetting(&#39;forums_edit_extend_vfile&#39;, &#39;vfilenew&#39;, $forum[&#39;vfile&#39;], &#39;text&#39;);</pre>

<p>//----edit找到以下代码</p>

<pre>
&#39;styleid&#39; =&gt; $_G[&#39;gp_styleidnew&#39;],</pre>

<p>在下面添加</p>

<p>//----edit</p>

<pre>
&#39;ffile&#39; =&gt; $_G[&#39;gp_ffilenew&#39;],

&#39;vfile&#39; =&gt; $_G[&#39;gp_vfilenew&#39;],</pre>

<p>//----edit</p>

<p>第三步:修改source/module/forum/forum_forumdisplay.php</p>

<p>找到以下代码</p>

<pre>
include template($template);替换成</pre>

<p>//eidt</p>

<pre>
if($_G[&#39;forum&#39;][&#39;ffile&#39;])
    $skinfile=$_G[&#39;forum&#39;][&#39;ffile&#39;];
else
    $skinfile = $template;

include template($skinfile);</pre>

<p>//eidt</p>

<p>第四步:修改source/module/forum/forum_viewthread.php</p>

<p>找到以下代码</p>

<pre>
include template(&#39;diy:forum/viewthread&#39;.$sufix.&#39;:&#39;.$_G[&#39;fid&#39;]);替换成</pre>

<p>//eidt</p>

<pre>
if($_G[&#39;forum&#39;][&#39;vfile&#39;]){
    include template($_G[&#39;forum&#39;][&#39;vfile&#39;]);
}else{
    include template(&#39;diy:forum/viewthread&#39;.$sufix.&#39;:&#39;.$_G[&#39;fid&#39;]);
}</pre>

<p>//eidt</p>

<p>第五步:修改source/language/lang_admincp.php</p>

<p>找到以下代码</p>

<pre>
&#39;forums_edit_extend_threadcache_comment&#39; =&gt; &#39;此功能可以将游客经常访问的主题临时缓存起来,缓解大型服务器压力。系数范围 0~100,建议数值 20 ~ 40,0 为关闭缓存。在磁盘空间允许的情况下,适当调高缓存系数,可以提高缓存效果</pre>

<p>注:版块设置完毕后请到 基本设置 -&gt; 站点页面缓存设置,调整其缓存时间。&#39;,在下面添加</p>

<p>//----edit</p>

<pre>
&#39;forums_edit_extend_ffile&#39; =&gt; &#39;版块模板文件:&#39;,

&#39;forums_edit_extend_ffile_comment&#39; =&gt; &#39;填写格式如forum/forumdisplay,请在特殊需要时进行设置,若为空则默认为forumdisplay&#39;,

&#39;forums_edit_extend_vfile&#39; =&gt; &#39;版块主题模板文件:&#39;,

&#39;forums_edit_extend_vfile_comment&#39; =&gt; &#39;填写格式如forum/viewthread,请在特殊需要时进行设置,若为空则默认为viewthread&#39;,</pre>

<p>//----edit</p>

<p>第六步:进入后台更新缓存后进入【论坛/版块/编辑/扩展设置】即可看到相应的设置</p>

<p>设置:版块模板文件、版块主题模板文件</p>

<p>注意:设置模板文件不需要填写此文件的后缀名</p>

<p>例子:模板文件为test.htm则只需填写forum/test即可<br />
<br />
源文地址:https://blog.csdn.net/weixin_28689809/article/details/116524606<br />
<br />
注:此方法要修改数据库、php文件,步骤繁琐,好处就是:应该会比插件改模板运行效率要高。</p>

杰克工作室 发表于 2023-3-13 16:36

discuz如何在插件里面控制调用模版文件呢》

<pre>
分享下代码

&lt;?php
class plugin_bbs{
&nbsp; &nbsp; function common(){
&nbsp; &nbsp; &nbsp; &nbsp; //模块执行前调用,全局函数
&nbsp; &nbsp; &nbsp; &nbsp; global $_G;
&nbsp; &nbsp; &nbsp; &nbsp; $style_id = 14;//模块的id 我这里写死了,在你后台添加风格模版的时候可以看到styleid

&nbsp; &nbsp; &nbsp; &nbsp; if(getcookie(&quot;app&quot;)){ //判断条件,可以不要
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($style_id ){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadcache(&quot;style_&quot;.$style_id);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($_G[&#39;cache&#39;][&#39;style_&#39;.$style_id]){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_G[&#39;style&#39;] = $_G[&#39;cache&#39;][&#39;style_&#39;.$style_id];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define(&quot;IMGDIR&quot;,$_G[&#39;style&#39;][&#39;imgdir&#39;]);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define(&quot;STYLEID&quot;,$_G[&#39;style&#39;][&#39;styleid&#39;]);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define(&quot;VERHASH&quot;,$_G[&#39;style&#39;][&#39;verhash&#39;]);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define(&quot;TPLDIR&quot;,$_G[&#39;style&#39;][&#39;tpldir&#39;]);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; define(&quot;TEMPLATEID&quot;,$_G[&#39;style&#39;][&#39;templateid&#39;]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }
}</pre>

<p>源文地址:https://www.cnblogs.com/57sy/archive/2012/12/04/3203715.html</p>
页: [1]
查看完整版本: Discuz! 中实现不同版块使用不同的模板文件的方法