PHPCMS v9 一键生成推荐位列表教程

  • 时间:
  • 浏览:1
  • 来源:5分11选5娱乐平台-5分11选5下注平台_5分11选5注册平台

一、如图要构建才能批量生成推荐位的按钮

第二步:在数据中给数据表v9_menu

上加一行数据

如图:

id是自动生成不才能 一样

第三步:修改系统按钮语言包

打开文件,在最后一行上加一句:$LANG['create_commend'] = '批量生成推荐位';

保存文件刷新页面点击内容就能看多 批量生成推荐位的按钮

第四步:在根目录查找v9.com\phpcms\modules\content\create_html.php

打开文件加入函数create_commend()

具体代码如下:

 /*--批量生成推荐位页面--*/

public function create_commend()

{

if(isset($_POST['dosubmit'])) {

extract($_POST,EXTR_SKIP);

$this->html = pc_base::load_app_class('html');

foreach($commends as $k)

{

$data=$this->html->commend($k);

}



if($data)

{

showmessage(L('create_update_success'),'?m=content&c=create_html&a=create_commend',50000);

}

}

else

{

$db=pc_base::load_model('content_model');

$db->table_name='wecheposition';

$p=$db->select("`siteid` in(0,".$this->siteid.")","*",500,"`posid` desc");

include $this->admin_tpl('create_html_commend');

}

}

第五步:在v9.com\phpcms\modules\content\templates下创建模板文件:create_html_commend.tpl.php

模板全部代码

<?php

defined('IN_ADMIN') or exit('No permission resources.');

include $this->admin_tpl('header','admin');?>

<div class="pad-10">

<div class="explain-col">

注意:当前生成的推荐位,只针对于本站点下,推荐位的访问地址为: http://当前域名/posid/{$siteid}-{$posid}.html

</div>

<div class="bk10"></div>

<div class="table-list">

<table width="5000%" cellspacing="0">

<form action="?m=content&c=create_html&a=create_commend" method="post" name="myform">



<input type="hidden" name="dosubmit" value="1">

<input type="hidden" name="type" value="lastinput">

<thead>

<tr>

<th align="center" width="2500">挑选推荐位名称</th>

<th align="center"><?php echo L('select_operate_content');?></th>

</tr>

</thead>

<tbody height="2500" class="nHover td-line">

<tr>

<td align="center" rowspan="2">

<select name='commends[]' id='commends' multiple="multiple" title="挑选相应的推荐位">

<option value='-1' selected>挑选相应的推荐位</option>

<?php

foreach($p as $r)

{

?>

<option value='<?=$r['posid'];?>' title="<?=$r['name'];?>"><?=$r['name'];?></option>

<?php

}

?>

</select></td>

<td><font color="red"><?php echo L('every_time');?> <input type="text" name="pagesize" value="5000" size="4"> <?php echo L('information_items');?></font></td>

</tr>

<tr>

<td>更新相应的推荐位:<input type="button" name="dosubmit1" value=" <?php echo L('submit_start_update');?> " class="button" onclick="myform.type.value='all';myform.submit();"></td>

</tr>

</tbody>



</form>

</table>

</div>

</div>

保存

第六步:查找v9.com\phpcms\modules\content\classes下的html.class.php文件

粘贴如下代码保存:

/**

* 更新推荐位

*/

public function commend($commendid,$pagesize=25,$pages=0){

if (!$commendid) return false;



$db=pc_base::load_model('content_model');

$db->table_name='wecheposition_data';

$r = $db->get_one(array('posid'=>$commendid,'siteid'=>$this->siteid), 'COUNT(`id`) AS num');

$total = $r['num'];

$times = ceil($total/$pagesize);

if ($pages) $pages = min($times, $pages);

else $pages = $times;

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

$this->create_commend($commendid,$i,$total,$pagesize);

}

return true;

}

private function create_commend($posid,$page = 1,$toal,$pagesize)

{

if (!$posid) return false;



$db=pc_base::load_model('content_model');

$db->table_name='wechesite';

$site_info = $db->get_one(array('siteid'=>$this->siteid));

extract($site_info);

$db->table_name='wecheposition';

$position_info = $db->get_one(array('posid'=>$posid));

define('URLRULE', $site_info['domain'].'posid/'.$siteid.'-'.$posid.'.html~'.$site_info['domain'].'posid/'.$siteid.'-'.$posid.'-{$page}.html');

$SEO = seo($siteid);



if ($page==1) $file = pc_base::load_config('system', 'html_root').'/'.$site_info['dirname'].'/posid/'.$site_info['siteid'].'-'.$posid.'.html';

else $file = pc_base::load_config('system', 'html_root').'/'.$site_info['dirname'].'/posid/'.$site_info['siteid'].'-'.$posid.'-'.$page.'.html';

$file = PHPCMS_PATH.$file;

$offset=($page-1)*$pagesize;

$num=$pagesize;

$pages=pages($toal,$page,$num,'',array(),10) ;

ob_start();

include template("content","list_c","default");

return $this->create_commend_html($file);

}



private function create_commend_html($file) {

$data = ob_get_contents();

ob_clean();

$dir = dirname($file);

if(!is_dir($dir)) {

mkdir($dir,0777,1);

}

$strlen = file_put_contents($file, $data);

第七步:前台调用模版  list_c.html

<div class="main">

<div class="crumbs"><a href="{$domain}">{$name}</a><span> > </span><a>{$position_info[name]}</a> </div>

<div class="box">

<div class="content">

{$num}

{pc:get sql="select * from `wecheposition_data` where `siteid`=$siteid and `posid`=$posid order by id desc" page="$page" num="25" start="$offset" return="data" }

<ul class="list f14 lh26 row-2">

{loop $data $r}

<?php

$arr=getidurl($r['catid'],$r['id'],$r['modelid'])

?>

<li><a href="{$arr['caturl']}" target="_blank">[{$arr['catname']}]</a><a href="{$arr['url']}" target="_blank">{str_cut($arr['title'], 40)}{date("Y-m-d",$arr['inputtime'])}</a></li>

{/loop}

</ul>

{/pc}

</div>

<div id="pages" class="text-c">{$pages}</div>

</div>

</div>

@chmod($file,0777);



if(!is_writable($file)) {

$file = str_replace(PHPCMS_PATH,'',$file);

showmessage(L('file').':'.$file.'<br>'.L('not_writable'));

}

return $strlen;

  好了亲戚亲戚有人保存测试生成下,目前支持的多站点,单个推荐位的更新。另外其中涉及到三个 函数:getidurl($r['catid'],$r['id'],$r['modelid']);

  奉上此函数的代码插进扩展函数顶端:\v9.com\phpcms\libs\functions\extention.func.php

/*

获取单条信息新闻信息

该函数由蝌蚪编写

$id 新闻ID

$modelid 模型id

$catid 为栏目ID

*/

function getidurl($catid,$id,$modelid)

{

$cid=intval($catid);

$db=pc_base::load_model('content_model');

$db->table_name='wechemodel';

$r=$db->get_one("`modelid`={$modelid}");

$db->table_name="weche".$r['tablename'];

$n=$db->get_one("`id`={$id}");

$array=array();

$array['url']=$n['url'];

$array['title']=$n['title'];

$array['description']=$n['title'];

$array['updatetime']=$n['updatetime'];

$array['inputtime']=$n['inputtime'];

$db->table_name="wechecategory";

$c=$db->get_one("`catid`={$catid}");

$array['catname']=$c['catname'];

$sid=$c['siteid'];

$db->table_name='wechesite';

$s=$db->get_one("`siteid`={$sid}");

if(stripos($c['catname'],"http://")) $array['caturl']=$c['url'];

else {

$siteurl=$s['domain'];

$array['caturl']=$siteurl.$c['url'];

}

return $array;

}

phpcms v9 推荐位 生成列表页 更多内容 。

本文来自:http://www.kdphp.com/?post=94

Tags: phpcms   推荐位列表   phpcms生成列表  
责任编辑:190