标题上的可能无法表达出我要做的东西,简单解释下:
在做模板下载时,有时候没有网址演示站,只是上传了一些截图,这些图片在帖子里全都插入很占地方,帖子拉的很长,所以想做个单独页面来显示本帖所有图片。
****点击我预览本帖图片demo****
使用自定义页面和帖内图片调用的方法:
[tem]1.自定义页面php文件[/tem]
以下代码做成php文件,命名demo.php,放到根目录。
- <?php
- if(!$_GET[tid]) {
- header('Location: /');
- }
- define('CURSCRIPT', 'demo');
- define('CURMODULE', 'index');
- require './source/class/class_core.php';
- $discuz = & discuz_core::instance();
- $discuz->init();
- loadcache('diytemplatename');
- $navtitle = '';
- $metakeywords = '';
- $metadescription ='';
- runhooks();
- include template('diy:portal/demo');
- ?>
复制代码 因为之后需要获取tid来查询相关内容,所以这里写了个判断,如果没有tid,就返回首页,要不然直接访问这个demo.php时会报错。
[tem]2.图片展示页面[/tem]
以下代码做成php文件,命名demo.php,放到template/当前风格目录/portal内。
- <?php echo'无主题信息'; exit;?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"><head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>图片演示 - <!--{$_G['setting'][sitename]}--></title>
- <meta name="keywords" content="$metakeywords">
- <meta name="description" content="$metadescription">
- <script>
- function setTab(name, cursel) {
- cursel_0 = cursel;
- for (var i = 1; i <= links_len; i++) {
- var menu = document.getElementById(name + i);
- var menudiv = document.getElementById("con_" + name + "_" + i);
- if (i == cursel) {
- menu.className = "off";
- menudiv.style.display = "block";
- }
- else {
- menu.className = "";
- menudiv.style.display = "none";
- }
- }
- }
- function Next() {
- cursel_0++;
- if (cursel_0 > links_len) cursel_0 = 1
- setTab(name_0, cursel_0);
- }
- var name_0 = 'one';
- var cursel_0 = 1;
- var ScrollTime = 5000; //循环周期,可任意更改(毫秒)
- var links_len, iIntervalId;
- onload = function() {
- var links = document.getElementById("tab1").getElementsByTagName('li')
- links_len = links.length;
- for (var i = 0; i < links_len; i++) {
- links[i].onmouseover = function() {
- clearInterval(iIntervalId);
- this.onmouseout = function() {
- iIntervalId = setInterval(Next, ScrollTime);;
- }
- }
- }
- document.getElementById("con_" + name_0 + "_" + links_len).parentNode.onmouseover = function() {
- clearInterval(iIntervalId);
- this.onmouseout = function() {
- iIntervalId = setInterval(Next, ScrollTime);;
- }
- }
- setTab(name_0, cursel_0);
- iIntervalId = setInterval(Next, ScrollTime);
- }
- </script>
- <style type="text/css">
- a:link{color: #000;text-decoration: none;}
- a:visited{text-decoration: none;color: #000;}
- a:hover{text-decoration: none;color: #000;}
- a:active{text-decoration: none;color: #000;}
- html, body, div, img{font-size:12px;margin:0;padding:0;}
- body{background-color: #ddd;}
- html, body{font-size:12px;}
- .cl{clear:both;}
- .head{position:fixed;top:0;width:100%;left: 0;_position:absolute;_width: expression(offsetParent.clientWidth);_top: expression(offsetParent.scrollTop);}
- html{_background: url(about:black) no-repeat fixed}
- .tab{height:45px;font-family:"Microsoft Yahei", Tahoma, Geneva, sans-serif;line-height:45px;width:100%;overflow:hidden;background:#4d4d4d;font-size:14px;margin:0;padding:0;color:#fff;font-weight:bold;text-shadow:1px 1px #12588A;}
- .td_l{float:left;padding:0 0 0 35px;text-align:left;}
- .td_r a, .td_l h1, .td_l a{font-size:14px;color:#fff;display:inline;text-decoration:none;padding:0 5px;}
- .td_l h3{font-size:14px;color:#fff;display:inline;text-decoration:none;padding:0 5px;color:#F00}
- .td_r{text-align:right;float:right;padding:0 30px 0 0;}
- .td_r a{color:#fff;padding:0 15px;background:#BD192D;display:block;float:left;font-weight:bold;}
- .td_r a:hover{background:#830010;}
- .bg{background:#fff;height:35px;overflow:hidden;border-bottom:1px solid #ccc;}
- .menu{padding:0 30px 0 35px;position:relative;top:-34px;height:34px;overflow:hidden;}
- .menu a li{color:#333;display:block;float:left;text-decoration:none;padding:0 15px;position:relative;height:30px;line-height:30px;overflow:hidden;background:#fff;}
- .menu a li.off{background:#f8f8f8;color:#000;border:1px solid #ccc;border-radius: 3px;}
- .menu .tip{float:left;margin-left:10px;font-family:宋体;background:#FFFFDD;color: #DB7C22;border: solid 1px #E3E197;border-radius: 2px;padding:5px 10px;}
- .menu .tip span{color:red;cursor:pointer;padding-left:5px;}
- .menudiv{text-align: center;padding-top: 5px;font-size: 30px;font-weight: bold;margin-top: 80px;margin-right: auto;margin-bottom: 0;margin-left: auto;background-repeat: no-repeat;}
- img{cursor:pointer;}
- .hide{display:none;}
- </style>
- </head>
-
- <body>
- <div class="head">
- <div class="tab">
- <!--{eval $threaddatas = DB::fetch_all("SELECT tid,pid,subject,author,authorid FROM ".DB::table('forum_post')." WHERE `tid`= '$_GET[tid]' AND `first`=1;");}-->
- <!--{loop $threaddatas $threaddata}-->
- <div class="td_l">
- <h1>
- <a href="forum.php?mod=viewthread&tid=$threaddata['tid']">
- $threaddata['subject']
- </a>
- - 效果演示
- </h1>
- <h3>
- 图片来自网页截图,实际可能因完善或修复而有变动。
- </h3>
- </div>
- <div class="td_r">
- <a target="_blank" href="forum.php?mod=viewthread&tid=$threaddata['tid']">
- 返回原帖
- </a>
- <a href="home.php?mod=space&uid=$threaddata['authorid']" title="$threaddata['author']主页"><i class="fa fa-envelope-o fa-fw"></i>By $threaddata['author']</a>
- </div>
- <!--{/loop}-->
- </div>
- <div class="bg">
- </div>
- <div class="tab1" id="tab1">
- <div class="menu">
- <!--{eval $tbid = DB::result(DB::query("SELECT tableid FROM ".DB::table('forum_attachment')." WHERE `tid`= '$_GET[tid]'"));}-->
- <!--{if $tbid}-->
- <!--{eval $piclists = DB::fetch_all("SELECT attachment,remote,aid,description,filename,pid FROM ".DB::table('forum_attachment_'.$tbid.'')." WHERE `tid`= '$_GET[tid]' AND `isimage`=1;");}-->
- <!--{loop $piclists $key $piclist}-->
- <!--{eval $ynfirst = DB::fetch_all("SELECT first FROM ".DB::table('forum_post')." WHERE `pid`= '$piclist[pid]';");}-->
- <!--{loop $ynfirst $va}-->
- <!--{eval $keys = $key+1;}-->
- <!--{if $va['first'] == 1}-->
- <a href="javascript:void(0);">
- <li id="one$keys" onclick="setTab('one',$keys)">
- <!--{if $piclist['description']}-->$piclist['description']<!--{else}-->$piclist['filename']<!--{/if}-->
- </li>
- </a>
- <!--{/if}-->
- <!--{/loop}-->
- <!--{/loop}-->
- <!--{else}-->
- <a><li style="text-align: center; width: 100%;">本帖无图,返回看文字吧。。。</li></a>
- <!--{/if}-->
- </div>
- <div class="cl">
- </div>
- </div>
- </div>
- <div class="menudiv">
- <!--{loop $piclists $key $piclist}-->
- <!--{eval $keys = $key+1;}-->
- <div id="con_one_$keys" style="display:none;">
- <!--{if $piclist['remote'] == 0}--><img src="data/attachment/forum/$piclist['attachment']"/><!--{else}--><img src="http://file.cmsbj.cn/cmsbj_file/forum/$piclist['attachment']"/><!--{/if}-->
- </div>
- <!--{/loop}-->
- </div>
- <div style="display:none">
- </div>
- </body>
- </html>
复制代码 这样,访问域名/demo.php?tid=主题id就可以显示这个主题的所有图片。
补充说明:以上使用的discuz自定义可diy页面,模板种查询数据。模板文件的命名可在include template('diy:portal/demo');里修改。
20161224 更新
修复会将回复楼内附件也调用的问题。
20180417 更新
增加runhooks();让插件钩子可以正常使用。
|