如題,如果你在使用PHPCMS V9的時候需要在不同的站點之間調用推薦位可能會出現鏈接的URL為空的情況,具體解決辦法如下,該辦法適合20130522 之前版本.
一、在自定義函數中加入下面的函數:
- /**
- * 獲取內容地址
- * @param $catid 欄目ID
- * @param $id 文章ID
- * @param $allurl 是否以絕對路徑返回
- */
- function go_dusion($catid,$id, $allurl = 0) {
- static $category;
- if(emptyempty($category)) {
- $siteids = getcache('category_content','commons');
- $siteid = $siteids[$catid];
- $category = getcache('category_content_'.$siteid,'commons');
- }
- if($siteid == '' || emptyempty($siteid)) {
- $siteids = getcache('category_content','commons');
- $siteid = $siteids[$catid];
- $category = getcache('category_content_'.$siteid,'commons');
- }
- $id = intval($id);
- if(!$id || !isset($category[$catid])) return '';
- $modelid = $category[$catid]['modelid'];
- if(!$modelid) return '';
- $db = pc_base::load_model('content_model');
- $db->set_model($modelid);
- $r = $db->get_one(array('id'=>$id), '`url`');
- if (!emptyempty($allurl)) {
- if (strpos($r['url'], '://')===false) {
- if (strpos($category[$catid]['url'], '://') === FALSE) {
- $site = siteinfo($category[$catid]['siteid']);
- $r['url'] = substr($site['domain'], 0, -1).$r['url'];
- } else {
- $r['url'] = $category[$catid]['url'].$r['url'];
- }
- }
- }
- return $r['url'];
- }
第二:在content/classes/content_tag.class.php 的 public function position($data)函數中,代碼如下:
- /**
- * 推薦位
- * @param $data
- */
- public function position($data) {
- $sql = '';
- $array = array();
- $posid = intval($data['posid']);
- $order = $data['order'];
- $thumb = (emptyempty($data['thumb']) || intval($data['thumb']) == 0) ? 0 : 1;
- //Du修改
- if(isset($data['siteid']) && is_numeric($data['siteid'])){
- $siteid = $data['siteid'];
- }else{
- $siteid = $GLOBALS['siteid'] ? $GLOBALS['siteid'] : 1;
- }
- $catid = (emptyempty($data['catid']) || $data['catid'] == 0) ? '' : intval($data['catid']);
- if($catid) {
- $siteids = getcache('category_content','commons');
- if(!$siteids[$catid]) return false;
- $siteid = $siteids[$catid];
- $this->category = getcache('category_content_'.$siteid,'commons');
- }
- if($catid && $this->category[$catid]['child']) {
- $catids_str = $this->category[$catid]['arrchildid'];
- $pos = strpos($catids_str,',')+1;
- $catids_str = substr($catids_str, $pos);
- $sql = "`catid` IN ($catids_str) AND ";
- } elseif($catid && !$this->category[$catid]['child']) {
- $sql = "`catid` = '$catid' AND ";
- }
- if($thumb) $sql .= "`thumb` = '1' AND ";
- if(isset($data['where'])) $sql .= $data['where'].' AND ';
- if(isset($data['expiration']) && $data['expiration']==1) $sql .= '(`expiration` >= /''.SYS_TIME.'/' OR `expiration` = /'0/' ) AND ';
- $sql .= "`posid` = '$posid' AND `siteid` = '".$siteid."'";
- $pos_arr = $this->position->select($sql, '*', $data['limit'],$order);
- if(!emptyempty($pos_arr)) {
- foreach ($pos_arr as $info) {
- $key = $info['catid'].'-'.$info['id'];
- $array[$key] = string2array($info['data']);
- $array[$key]['url'] = go_dusion($info['catid'],$info['id']);
- $array[$key]['id'] = $info['id'];
- $array[$key]['catid'] = $info['catid'];
- $array[$key]['listorder'] = $info['listorder'];
- } //Vevb.com
- }
- return $array;
- }
即可,注意看兩處紅色區域,11-16行是為了獲取siteID 可以根據情況不修改也可以42行,即將原來 的go 改為 go_dusion其它不變即可.
新聞熱點
疑難解答