discuz 把主帖背景作为body背景

discuz教程
默认情况下,帖子设置楼层背景只限于本楼层,现在我要将它改为:当主帖设置了背景,就把这个背景作为整个页面(body)的背景,回复楼层不变,依然是局限于自己楼层。

完整经过:

1.获得主题帖背景图。

在主帖设置好背景图后,会在帖子内容字段“message”中存储一段如“[ postbg]bg5.png[ /postbg]”的标签,系统处理之后将它变成了

$_G['forum_posthtml']['header'][$post[pid]]

复制代码

这句在viewthread_node_body.htm里,会生成一段样式代码,例如

<style type="text/css">#pid1498{background-image:url("static/image/postbg/bg1.png");}</style>

复制代码

图片地址看到了,但需要提取下才能拿出来用。

2.把样式代码中的图片提取出来。

正则提取语句

<!--{eval $mage_match=preg_match("|background-image:url\((.*)\);|U", $_G['forum_posthtml']['header'][$post[pid]], $result);}-->

复制代码

$result是个数组,两项:

$result[0]是background-image:url("static/image/postbg/bg1.png");

$result[1]是"static/image/postbg/bg1.png"

完整的代码,这里以$result[1]为例,可在viewthread_node_body.htm里顶部加一段

<!--{if $post['first']}-->

<!--{eval $mage_match=preg_match("|background-image:url\((.*)\);|U", $_G['forum_posthtml']['header'][$post[pid]], $result);}-->

<style>body{ {$result[0]} }</style>

<!--{/if}-->

复制代码

意思是,如果是主帖,body使用提取出来的主帖楼层背景。

3.把主帖楼层里的背景去掉

在viewthread_node_body.htm里查找

$_G['forum_posthtml']['header'][$post[pid]]

复制代码

给它套上判断,即

<!--{if !$post['first']}-->$_G['forum_posthtml']['header'][$post[pid]]<!--{/if}-->

复制代码

帖子背景在回复帖生效。

end。

* 如果出现设置过帖子背景后,再编辑时,编辑器无法切换可视化、部分按钮失效的情况,打开/template/default/common/editor.htm,顶部的

<script type="text/javascript" src="{$_G['setting']['jspath']}common_postimg.js?{VERHASH}"></script>

复制代码

改为

<script type="text/javascript" src="data/cache/common_postimg.js?{VERHASH}"></script>

复制代码

X3.4版本没有这句,加上就行了,这是自带问题,与俺无关,详情请访问官方论坛查询。

标签: