wordpress 调用函数更新文章 多站管理 Post操作就可以了
本帖最后由 finder 于 2014-12-28 15:13 编辑直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章如果你采集的文章直接使用一个post操作就可以了
方便实用 简单 何乐而不用呢
<?php
define( 'ABSPATH', dirname(__FILE__) . '/' );
require_once( ABSPATH . 'wp-config.php' );
require_once( ABSPATH . 'wp-settings.php' );
require_once( ABSPATH . 'wp-includes/class-wp.php' );
require_once( ABSPATH . 'wp-includes/functions.php' );
require_once( ABSPATH . 'wp-includes/plugin.php' );
$title = $_POST["title"];
$content = $_POST["content"];
$tags = explode("_",$_POST["tags"]);
$cate = $_POST["cate"];
//print_r $tags;
//
//
$wp = new WP();
$wp->main();
//
$my_post = array();
$my_post['post_title'] = $title;
$my_post['post_content'] = $content;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array($cate);
$my_post['tags_input'] = $tags;
//$my_post['tags_input'] = array('tag1', 'tag2');
//$my_post['post_status'] = 'future';
////$my_post['post_date'] = '2010-07-04 16:20:03';
// Insert the post into the database
$ret = wp_insert_post( $my_post );
echo $ret;
?>
下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
<?php
define( 'ABSPATH', dirname(__FILE__) . '/' );
require_once( ABSPATH . 'wp-config.php' );
require_once( ABSPATH . 'wp-settings.php' );
require_once( ABSPATH . 'wp-includes/class-wp.php' );
require_once( ABSPATH . 'wp-includes/functions.php' );
require_once( ABSPATH . 'wp-includes/plugin.php' );
$pic_name = $_POST["pic_name"];
$pic = $_POST["pic"];
if($pic != "" && $pic_name != "")
{
$path = "images/";
$pic_name = $path.$pic_name;
echo $pic_name;
echo "||";
error_reporting(0);
mkdir("images");
$handle = fopen($pic_name, 'w');
echo fwrite($handle,file_get_contents($pic));
}
$title = $_POST["title"];
$content = $_POST["content"];
$tags = explode("_",$_POST["tags"]);
$cate = $_POST["cate"];
//print_r $tags;
//
//
$wp = new WP();
$wp->main();
//
$my_post = array();
$my_post['post_title'] = $title;
$my_post['post_content'] = $content;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array($cate);
$my_post['tags_input'] = $tags;
//$my_post['tags_input'] = array('tag1', 'tag2');
//$my_post['post_status'] = 'future';
////$my_post['post_date'] = '2010-07-04 16:20:03';
// Insert the post into the database
$ret = wp_insert_post( $my_post );
echo $ret;
?>
我自己写的
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 火车头的wp免登陆接口就是利用wp_insert_post,用哈默的接口相对强大些 用xmlrpc不是更好吗 楼主辛苦了!~~
页:
[1]