您的位置:首页 > 编程语言 > PHP开发

关于yourphp内容管理系统开启伪静态之后volist调用排序

2016-12-10 01:35 375 查看
写这篇博客主要的目的是让大家开发起来少浪费一些时间在小问题上。

今日用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}"><img src="{$vo.thumb}"></a></span><a href="{$vo.url}" 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;
}

博主第一次写博客,可能写得很啰嗦,主要是太紧张,担心写不好,大家看不懂,写这篇博客主要的目的是让大家开发起来少浪费一些时间在小问题上(长沙臭豆腐)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐