wordpress长文章批量分页php代码

给wordpress长文章批量分页功能的php代码,残冰在此以图片类文章为例

<?php
set_time_limit(0);
ini_set(“memory_limit”,”2000M”);
echo “<meta http-equiv=’Content-Type’ content=’text/html; charset=utf-8′ />” ;

/*连接数据库*/
$conn = @mysql_connect(“localhost”,”root”,””);
if (!$conn){
die(“连接数据库失败:” . mysql_error());
}
mysql_select_db(“nvyou”, $conn);

mysql_query(“SET NAMES ‘utf8′”);

/*读取要修改的多图片文章*/

$Query=”select ID,post_content from wp_posts where post_content like ‘%<img %’ “; ;
$Result=mysql_query($Query);
$Number=mysql_num_rows($Result);
for($m=0;$m<$Number;$m++)
{
$Row=mysql_fetch_array($Result);
$id=$Row[ID];
$post_content=$Row[post_content];
$post_content=str_replace(“<img”,”**##<img”,$post_content);//此处把每个img标签前加上**##作为分隔符
$post_contentarr=explode(“**##”,$post_content);将所有的img分割成数组
$len=count($post_contentarr);
if($len>20){//如果img图片数超过20个,才开始分页
for($i=0;$i<$len;$i++)
{
if($i!=0&&$i%11==0)//此处就是每10个图片分一叶
{
$post_content=str_replace($post_contentarr[$i],”<!–nextpage–>”.$post_contentarr[$i],$post_content);//添加分页符
}
}
}

$post_content=str_replace(“**##<img”,”<img”,$post_content);去除分隔符**##

$post_content=str_replace(“**## <!–nextpage–> “,” <!–nextpage–> “,$post_content);

$sqlinsertcon=”UPDATE wp_posts SET post_content = ‘”.$post_content.”‘ WHERE ID=”.$id;

if(mysql_query($sqlinsertcon))
{
echo ‘UPsuccess’.$id.”</br>”;
}
else
{
mysql_error();
}
}

?>

未经允许不得转载:前端撸码笔记 » wordpress长文章批量分页php代码

上一篇:

下一篇: