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

一、如图要构建可以或许批量生成推荐位的按钮

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

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

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

添加一行数据

如图:

id是自动生成不需要一样

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

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

打开文件,在最后一行加上一句:$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',1000);
}
}
else
{
$db=pc_base::load_model('content_model');
$db->table_name='wecheposition';
$p=$db->select("`siteid` in(0,".$this->siteid.")","*",30,"`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">
留意:当前生成的推荐位,只针对付本站点下,推荐位的会见解点为: 当前域名/posid/{$siteid}-{$posid}.html
</div>
<div class="bk10"></div>
<div class="table-list">
<table width="100%" 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="250">选择推荐位名称</th>
<th align="center"><?php echo L('select_operate_content');?></th>
</tr>
</thead>
<tbody height="250" class="nHover td-line">
<tr>
<td align="center" rowspan="2">
<select multiple="multiple" style="height:200px; width:200px;" 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="100" 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').'http://down.chinaz.com/'.$site_info['dirname'].'/posid/'.$site_info['siteid'].'-'.$posid.'.html';
else $file = pc_base::load_config('system', 'html_root').'http://down.chinaz.com/'.$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);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/10622.html