如果您想发布多个项目,那么每个帖子只有几处会发生变化:
- 帖子的标题。
- 帖子内容
- 帖子的类别
- 关键字(可选,但我猜你正在使用它)。
RPC URL、用户名、密码和编码是标准的,因为我还假设您将其发布到同一个网站上。所以我们只需要将 4 个命名项存储在一个可以运行的数组中。我将项目存储在另一个数组中,所以我们有一个数组数组。
你可以很容易地写出这样的东西:
// We create a post array that contains an array per post.
// I put in the data index based. First item is title, second is content body, third is category, fourth is keywords.
$posts = array(
array('Title','Contents','category','keywords'),
array('Another post','More content','another category ID','etc.'),
// You can add more items if you want.
);
// These are just general settings that are the same for each post.
$rpcurl = 'http://www.yourwordpressblog.com/xmlrpc.php';
$username = 'myusername';
$password = 'mypassword';
$encoding ='UTF-8';
foreach($posts AS $Post)
{
// From the foreach we get an array with post data each cycle.
// To keep things a bit clear, I will extract the data to seperate variables..
$title = $Post[0];
$body = $Post[1];
$category = $Post[2];
$keywords = $Post[3];
wpPostXMLRPC($title,$body,$rpcurl,$username, $password,$category,$keywords,$encoding);
}