天天看點

關于yourphp内容管理系統開啟僞靜态之後volist調用排序

寫這篇部落客要的目的是讓大家開發起來少浪費一些時間在小問題上。

今日用yourphp内容管理系統做二次開發的時候遇到一個問題,就是網站開啟僞靜态之後,背景設定的排序無效,于是百度了一下,發現有很多人回答了,修改某某檔案222行為->(listorder desc)然而并沒有什麼卵用, 僞靜态根本不執行這個檔案,于是各種翻牆加交流群,請教大神都未果,是的,使用YP:list 可以設定排序,但是無法使用分頁。

清單頁模版提供的是:

<div class="list pic_list"><ul class="pic">

<volist name="list" id="vo" key="k" order="listorder desc">

<li><span><a href="{$vo.url}" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" ><img src="{$vo.thumb}"></a></span><a href="{$vo.url}" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank">{$vo.title}{$vo.listorder}</a></li>

</volist>

</ul></div>

<div id="pages" class="page">{$pages}</div>

是以我隻要找到list這個資料的由來就解決問題了,這貌似是yourphp2.*版本遺留下來的bug,我花了一天的時間查資料,請教大神,都沒有解決,突然靈光一現,我應該根據代碼的執行過程來尋找資料源,于是我根據背景網站更新裡面的更新清單頁的button,找到了觸發生成靜态頁的函數,接下來就是順藤摸瓜,哈哈

找到Lib/Action/AdminbaseAction.class.php的create_list()函數,将$list = $dao->field($field)->where($where)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();修改為$list = $dao->field($field)->where($where)->order('listorder desc')->limit($page->firstRow . ',' . $page->listRows)->select();就大功告成了,對了要記得更新清單頁....

public function create_list($catid,$p=1,$count=0)

    {

C('DEFAULT_THEME_NAME',$this->sysConfig['DEFAULT_THEME']);

C('HTML_FILE_SUFFIX',$this->sysConfig['HTML_FILE_SUFFIX']);

C('TMPL_FILE_NAME',str_replace('Admin/Default','Home/'.$this->sysConfig['DEFAULT_THEME'],C('TMPL_FILE_NAME')));

if(APP_LANG){

C('TMPL_CACHFILE_SUFFIX','_'.LANG_NAME.'.php');

$lang =  C('URL_LANG')!=LANG_NAME ? $lang = LANG_NAME.'/' : '';

L(include LANG_PATH.LANG_NAME.'/common.php');

$T = F('config_'.LANG_NAME,'', './Yourphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/'); 

}else{

L(include LANG_PATH.$this->sysConfig['DEFAULT_LANG'].'/common.php');

$T = F('config_'.$this->sysConfig['DEFAULT_LANG'],'', './Yourphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/');

}

$this->assign('T',$T);

foreach((array)$this->module as $r){

if($r['issearch'])$search_module[$r['name']] = L($r['name']);

}

$this->assign('search_module',$search_module);

$this->assign ( 'form',new Form());

$this->assign($this->Config);

$this->assign('Categorys',$this->categorys);

$this->assign('Module',$this->module);

$this->assign('Type',$this->Type);

$catid =intval($catid);

if(empty($catid)) $this->success (L('do_empty'));

$cat = $this->categorys[$catid];

$this->assign('catid',$catid);

if($cat['type']) return;

if(empty($cat['ishtml'])) return;

unset($cat['id']);

$this->assign($cat);

$cat['id']=$catid;

$bcid = explode(",",$cat['arrparentid']);

$bcid = $bcid[1];

if($bcid == '') $bcid=intval($catid);

$this->assign('bcid',$bcid);

$urlrule = geturl($cat,'',$this->Urlrule);

$url= ($p > 1 ) ? $urlrule[1] :  $urlrule[0];

$url = str_replace('{$page}', $p, $url);

if(strstr($url,C('HTML_FILE_SUFFIX'))){

$filename = basename($url,C('HTML_FILE_SUFFIX'));

$dir = dirname($url).'/';

}else{

$filename = 'index';

$dir= $url; 

}

$dir = substr($dir,strlen(__ROOT__.'/'));

if(empty($module))$module=$cat['module'];

$this->assign('module_name',$module);

$this->assign ( 'fields', F($cat['moduleid'].'_Field') ); 

$this->assign ( 'form',new Form());

if($cat['moduleid']==1){

$cat['listtype']=2;

$module = $cat['module'];

$dao= M($module);

$data = $dao->find($catid);

$seo_title = $cat['title'] ? $cat['title'] : $data['title'];

$this->assign ('seo_title',$seo_title);

$this->assign ('seo_keywords',$data['keywords']);

$this->assign ('seo_description',$data['description']);

$template = $cat['template_list']? $cat['template_list'] : 'index';

//手動分頁

$CONTENT_POS = strpos($data['content'], '[page]');

if($CONTENT_POS !== false){

$contents = array_filter(explode('[page]',$data['content']));

$pagenumber = count($contents);

for($i=1; $i<=$pagenumber; $i++) {

$pageurls[$i] = str_replace('{$page}',$i,$urlrule);

}

//生成分頁

foreach ($pageurls as $p=>$urls) {

$pages = content_pages($pagenumber,$p, $pageurls);

$this->assign ('pages',$pages);

$data['content'] = $contents[$p-1];

$this->assign ($data);

if($p > 1)$filename = basename($pageurls[$p]['1'],C('HTML_FILE_SUFFIX'));

//$this->buildHtml($filename,$dir,'Home/'.$template);

$r=$this->buildHtml($filename,$dir,'./Yourphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/Page_'.$template.C('TMPL_TEMPLATE_SUFFIX'));

}

}else{

$this->assign($data);

//$r=$this->buildHtml($filename,$dir,'Home/'.$template);

$r=$this->buildHtml($filename,$dir,'./Yourphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/Page_'.$template.C('TMPL_TEMPLATE_SUFFIX'));

}

}else{

$seo_title = $cat['title'] ? $cat['title'] : $cat['catname'];

$this->assign ('seo_title',$seo_title);

$this->assign ('seo_keywords',$cat['keywords']);

$this->assign ('seo_description',$cat['description']);

if($cat['listtype']==1){

$template_r = 'index';

}else{

$where = " status=1 ";

if($cat['child']){

$where .= " and catid in(".$cat['arrchildid'].")";

}else{

$where .=  " and catid=".$catid;

}

$module = $cat['module'];

$dao= M($module);

if(empty($count))$count = $dao->where($where)->count();

if($count){

import ( "@.ORG.Page" );

$listRows =  !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');

$page = new Page ( $count, $listRows ,$p );

$page->urlrule = $urlrule;

$pages = $page->show();

$field =  $this->module[$this->mod[$module]]['listfields'];

$field =  $field ? $field : 'id,catid,userid,url,username,title,title_style,keywords,description,thumb,createtime,hits';

$list = $dao->field($field)->where($where)->order('listorder desc')->limit($page->firstRow . ',' . $page->listRows)->select();

$this->assign('pages',$pages);

$this->assign('list',$list);

}

$template_r = 'list';

}

$template = $cat['template_list']? $cat['template_list'] : $template_r;

$r=$this->buildHtml($filename,$dir,'./Yourphp/Tpl/Home/'.$this->sysConfig['DEFAULT_THEME'].'/'.$cat['module'].'_'.$template.C('TMPL_TEMPLATE_SUFFIX'));

}

if($r) return true;

}

部落客第一次寫部落格,可能寫得很啰嗦,主要是太緊張,擔心寫不好,大家看不懂,寫這篇部落客要的目的是讓大家開發起來少浪費一些時間在小問題上(長沙臭豆腐)