<?php
//数据库连接信息
$mysql_conf = array(
'host' => '',
'db' => '',
'db_user' => '',
'db_pwd' => '',
);
//数据库连接
$mysqli = @new mysqli($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);
if ($mysqli->connect_errno) {
die("could not connect to the database:\n" . $mysqli->connect_error);//诊断连接错误
}
$mysqli->query("set names 'utf8';");//编码转化
$select_db = $mysqli->select_db($mysql_conf['db']);
if (!$select_db) {
die("could not connect to the db:\n" . $mysqli->error);
}
//wordpress后台分类ID
$cids = [3985,3915,3931,36,3983];
$html = '';
foreach ($cids as $k=>$v) {
$sql="SELECT ID,post_title,post_date,post_content FROM wp_posts,wp_term_relationships,wp_term_taxonomy WHERE ID=object_id and wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id and post_type='post' and post_status = 'publish' and wp_term_taxonomy.term_id = $v and taxonomy = 'category' order by ID desc limit 10";
$res = $mysqli->query($sql);
if (!$res) {
die("sql error:\n" . $mysqli->error);
}
$html .= "<div class='regCnt'><ul>";
while ($row = $res->fetch_assoc()) {
$html .= "<li><a href='https://xxx.com/?p=".$row['ID']."' target='_blank'>".$row['post_title']."</a></li>";
}
$html .= "</ul></div>";
}
echo $html;
$res->free();
$mysqli->close();
?>