實(shí)現(xiàn)dedecms圖集單擊圖片翻頁(yè)的功能_PHP教程
推薦:dedecms5.1升級(jí)sp1出現(xiàn)IfTagNull()錯(cuò)誤解決方法記錄最近有報(bào)告錯(cuò)誤說(shuō)從dedecms5.1升級(jí)sp1出現(xiàn)錯(cuò)誤,代碼大致如下: Fatal error: Call to undefined function IfTagNull() in /……/include/
題記:在很多相冊(cè)的網(wǎng)站中,都有這樣的功能:當(dāng)圖片分多頁(yè)顯示的情況下,點(diǎn)擊圖片會(huì)自動(dòng)翻頁(yè)到下一張圖片,接下來(lái)我們?cè)赿edecms4中實(shí)現(xiàn)這個(gè)功能。以下是實(shí)現(xiàn)方法:1、為了實(shí)現(xiàn)這個(gè)功能,我們首先需要獲得圖片頁(yè)面的當(dāng)前頁(yè)碼和總頁(yè)碼
編輯include/inc_archives_view.php文件
(1)找到function ParseDMFields,修改為:
| function ParseDMFields($pageNo,$ismake=1) { $this->NowPage = $pageNo; //獲得當(dāng)前頁(yè)面編號(hào) $this->Fields['cpagenum'] = $this->NowPage; if($this->SplitPageField!="" && isset($this->Fields[$this->SplitPageField])) { $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1]; } |
注意增加了如下代碼用來(lái)獲得當(dāng)前的頁(yè)碼:
| $this->Fields[’cpagenum’] = $this->NowPage; |
| <?php
…… $this->TotalPage = count($this->SplitFields); } //獲得當(dāng)前頁(yè)面總數(shù) $this->Fields['totalpage'] = $this->TotalPage; $this->LoadTemplet(); $this->ParseTempletsFirst(); } |
注意增加了如下代碼用來(lái)獲得總頁(yè)碼:
| $this->Fields[’totalpage’] = $this->TotalPage; |
2、接下來(lái)在模板中用js實(shí)現(xiàn)分析靜態(tài)頁(yè)面和動(dòng)態(tài)頁(yè)面以及向下翻頁(yè)
編輯article_image.htm或者你的圖集最終顯示的模板,增加如下js代碼:
| <script language="javascript">
var npage = {dede:field name='cpagenum'/}; var totalpage = {dede:field name='totalpage'/}; var filename=""; var curl=location.href; function goNextPic(){ str1 = /\.html/ig; str2 = /_/ig; r = curl.search(str1); r1 = curl.search(str2); if(r>0){ if(npage==1) filename = curl.substr(0,r); else filename = curl.substr(0,r1); if(npage==totalpage){ location.href = filename ".html"; } else{ location.href = filename "_" (npage 1) ".html"; } }else{ if(npage==totalpage){ location.href = "view.php?aid={dede:field name='id'/}"; } else{ location.href = "view.php?aid={dede:field name='id'/}&pageno=" (npage 1); } } } </script> |
在這個(gè)js腳本中,我們定義一個(gè)方法goNextPic用來(lái)切換到下一個(gè)圖片。
3、最后修改圖片輸出代碼,完成goNextPic方法調(diào)用
修改include/inc_channel_unit.php找到”//全部列出式或分頁(yè)式圖集”的部分。
修改類似(仔細(xì)看代碼,需要修改好幾個(gè)地方):
| $revalue = "<center><a href='$src' target='_blank'><img src='$src' alt='$alt' $iw border='0'/></a><br/>$alt<br/></center>\r\n";
|
為:
| $revalue = "<center><a href='javascript:goNextPic();'><img src='$src' alt='$alt' $iw border='0'/></a><br/>$alt<br/></center> ";
|
原文地址: http://www.blog-dragon.com/2007/12/dedecms-pic-gopage.html
分享:PHP教程:PHP編碼書寫規(guī)范1 文件結(jié)構(gòu) | |――images |――include |――parameter |――config |――function |――index images存放圖
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁(yè)面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問(wèn)控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語(yǔ)言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語(yǔ)言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- php 深入理解strtotime函數(shù)的使用詳解
- PHP 觀察者模式的實(shí)現(xiàn)代碼
- PHP中for循環(huán)語(yǔ)句的幾種“變態(tài)”用法
- PHP實(shí)用手冊(cè):PHP常用正則表達(dá)式收集
- 如何使用PHP調(diào)用TinyURL API
- 基于php上傳圖片重命名的6種解決方法的詳細(xì)介紹
- 解析php做推送服務(wù)端實(shí)現(xiàn)ios消息推送
- 《PHP設(shè)計(jì)模式介紹》第九章 觀測(cè)模式
- setcookie中Cannot modify header information-headers already sent by錯(cuò)誤的解決方法詳解
- PHP調(diào)用MsSQL Server 2012存儲(chǔ)過(guò)程獲取多結(jié)果集(包含output參數(shù))的詳解
- 相關(guān)鏈接:
- 教程說(shuō)明:
PHP教程-實(shí)現(xiàn)dedecms圖集單擊圖片翻頁(yè)的功能
。