|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 3 ?! ^' X! w- a j7 h! W! R
9 S2 r% W9 ^ C- r# A/ X) `直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
. P" ]4 F+ w' b( H( {$ n ?, s/ v* S& a8 G/ g
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
( y' J- B+ [- L
8 I! H' Z) C* c2 `; F/ i5 d2 e方便实用 简单 何乐而不用呢
7 V* h* |+ L1 K; v# `0 H/ {+ M- <?php7 \4 f9 ]! y- k* e% N
- * l. G* ~/ k! O# U, n
- define( 'ABSPATH', dirname(__FILE__) . '/' );; L F9 k1 D! n" K' l' v% V* ]9 E8 C
- require_once( ABSPATH . 'wp-config.php' );
' z* z& r" s& M! q0 w) y - require_once( ABSPATH . 'wp-settings.php' ); x. Z6 J3 Q x! @: |8 ]
- require_once( ABSPATH . 'wp-includes/class-wp.php' );* u1 |5 f4 k/ s: [
- require_once( ABSPATH . 'wp-includes/functions.php' );
. X$ L( v& l2 _9 x% Y - require_once( ABSPATH . 'wp-includes/plugin.php' );7 Y0 K# G' d1 _5 S# v B
- $title = $_POST["title"];1 _5 Z) G$ W% y. _% k
- $content = $_POST["content"];
! { o. Z' H" G! K - $tags = explode("_",$_POST["tags"]);+ X% t+ e+ h- U* Z
- $cate = $_POST["cate"];0 {( v" I% j' ^0 `" c
- //print_r $tags;# a3 V+ d2 a1 C# k
- //
X0 d- r3 e6 y6 n - //
5 u2 J7 n8 s+ y# o, N9 U! F - $wp = new WP();+ `& K0 ^, H5 [5 `5 k
- $wp->main();
# w* v: |5 X9 U1 u. p. z - //) F* p) E0 u$ a: a5 m e
- $my_post = array();
% U( f4 @3 [7 Z, o0 a - $my_post['post_title'] = $title;8 C7 T9 s! [; t7 Q
- $my_post['post_content'] = $content;
- n1 c, c- Y' N) x! c - $my_post['post_status'] = 'publish';
% n! X/ S1 z, O) |0 J% B - $my_post['post_author'] = 1;
* y- v; t0 E2 _ o - $my_post['post_category'] = array($cate);
' M5 h) B" O& c! q - $my_post['tags_input'] = $tags;
6 I9 Z& [, Z+ Z" Y. s - //$my_post['tags_input'] = array('tag1', 'tag2');
( i: v. G r- o7 `% P - //$my_post['post_status'] = 'future';" t2 C9 r1 x: ]/ ]
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
, i/ \( V: o& q0 P& p" f
! r" _7 g" n' W5 ]- |) y* @- // Insert the post into the database
: a) Q# B& V6 u - $ret = wp_insert_post( $my_post );( i5 P& O2 R+ q4 Z" d
- echo $ret;
8 ~/ r. B! u$ i& U! O1 E4 x - ?>
* L7 |* O" o" n7 X
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
# t$ o+ t6 p, O2 [+ Z0 m9 f- <?php8 Z# ^0 G" `) S
- define( 'ABSPATH', dirname(__FILE__) . '/' );
$ O$ ]/ K) B, c( M* o - require_once( ABSPATH . 'wp-config.php' );
# y# }+ w2 q5 h" k - require_once( ABSPATH . 'wp-settings.php' );
& k r, R, B% P' t2 ` - require_once( ABSPATH . 'wp-includes/class-wp.php' );
% v+ O8 @7 |0 Y, ~ - require_once( ABSPATH . 'wp-includes/functions.php' );
& C5 } W' ], I - require_once( ABSPATH . 'wp-includes/plugin.php' );
& b G+ w* @: o- Y - $pic_name = $_POST["pic_name"];
- w7 m% w! J* c; b9 o' v5 Z - $pic = $_POST["pic"];
# r; ]( F* m7 K% Q4 J" j& X - if($pic != "" && $pic_name != "")
: Z6 c/ G' ~# O; p& o; w - {
" g( `" d% u p& P - $path = "images/";
. p$ ]9 e9 L$ t4 i5 ~( J - $pic_name = $path.$pic_name;. D) v; h& o) P1 D
- echo $pic_name;$ k- a8 e1 t* P- K7 x- m5 j4 \, y/ g
- echo "||";7 E, F- j `) g7 p+ K s
- error_reporting(0);* s5 E- M2 T) K \* E3 t
- mkdir("images");- R. \( z& s+ G V: O
- $handle = fopen($pic_name, 'w');$ O$ H7 W4 U1 F
- echo fwrite($handle,file_get_contents($pic));: K" _# o" {9 s
- }- H" d+ x$ D- G. r
, {. a5 E- k' z# n- $title = $_POST["title"];
5 M4 E3 ~! o1 Z$ Q+ l5 ]' o4 B - $content = $_POST["content"];
, ~) k' u1 K j5 I% A, M" V6 S - $tags = explode("_",$_POST["tags"]);
' i" n6 v% @0 N* j' z - $cate = $_POST["cate"];
$ \+ }% r! _3 m( ]& x+ Q - //print_r $tags;
, f2 e- w/ w: A; U$ T( r - //' }0 T8 t) R9 d" T3 t8 p
- //6 Q j3 r! h; |. g* L8 B! c
- $wp = new WP();
, k3 C4 o3 Y! P* E7 m% _3 { - $wp->main();8 Z6 R; }% ?1 s! s" `
- //$ P/ f# @5 e, T+ n7 w
- $my_post = array();8 a I! n! W: i# k$ J) {& X: E$ u
- $my_post['post_title'] = $title;
3 _) n% \; x/ G3 H- g3 |8 U7 m - $my_post['post_content'] = $content;. F# B0 {8 ]6 Z& d! M' c
- $my_post['post_status'] = 'publish';
3 u3 _9 t/ m+ d: L+ f9 s - $my_post['post_author'] = 1;" Z {: @" x7 O5 w# ?& [/ H) e; f1 W
- $my_post['post_category'] = array($cate);
- d, p) [7 H8 u$ ^- \, x - $my_post['tags_input'] = $tags;
* E5 ~: [, J: [! a/ R - //$my_post['tags_input'] = array('tag1', 'tag2');( Z2 l2 _ g0 ~5 Q: V
- //$my_post['post_status'] = 'future';
8 a% o% e" S, p! G9 h - ////$my_post['post_date'] = '2010-07-04 16:20:03';( `# `. ~$ o8 y
* N) [! M% _6 g$ I- // Insert the post into the database
- [7 `5 J9 V! W1 n+ l5 g - $ret = wp_insert_post( $my_post );
8 P1 R- l9 k( ~) ~$ a- V; D+ } - echo $ret;
- `4 t4 P% O) n0 v) \) C9 I4 C - ?>
& @! G- ?$ k; n3 I( V
复制代码 我自己写的
# l, e/ r& `; k% Y插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|