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