|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 o( p$ B% Z/ R2 r/ M
& q! ]2 F% N. q" S6 [1 n) [' b直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
6 C1 L( H( Y6 f6 B$ ~" q0 z4 L4 F1 H! F3 W6 T
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了
6 ]3 ^5 J" M9 V$ T$ Z. A* A9 J# ~* ?6 d) ~
方便实用 简单 何乐而不用呢
7 c E1 d+ k, g% N" r- <?php
; U) @" R2 x4 }$ i" d
0 K6 X' O2 c7 ?9 _/ @' H$ A- define( 'ABSPATH', dirname(__FILE__) . '/' );
3 b1 h8 T5 |1 j9 Z - require_once( ABSPATH . 'wp-config.php' );6 T, f! w5 D2 E4 T2 @ x
- require_once( ABSPATH . 'wp-settings.php' );3 r7 B# N$ w) c- T) |/ E2 q8 O
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
, ]* U5 v E1 v, ? - require_once( ABSPATH . 'wp-includes/functions.php' );
% h6 t! A$ m/ M- ^ y8 \ - require_once( ABSPATH . 'wp-includes/plugin.php' );. L$ M$ T3 e$ A3 U5 `
- $title = $_POST["title"];9 T. v. a( e; f! r0 u
- $content = $_POST["content"];1 ?7 p* E& ?, d N% `9 l0 k8 o
- $tags = explode("_",$_POST["tags"]); W" _1 p: i8 m- x) j7 E4 g
- $cate = $_POST["cate"];% x$ G8 w! Y+ U2 g) s
- //print_r $tags;) H0 x) P5 E6 Z' s3 h. A# O
- //0 N) Z; R) I1 \+ J5 ?- V9 n. [
- //
. j! |+ B. r6 y# O3 {# g6 _8 G( [ - $wp = new WP();
1 _* E: S" Y( M0 G5 N5 r - $wp->main();) w& _# n$ x$ H) g1 u: P
- //
( G+ O8 a& n; n# k - $my_post = array();
5 V8 @- T5 ~0 x' w* q/ C - $my_post['post_title'] = $title;
7 I/ T- K5 c7 F* m) T - $my_post['post_content'] = $content;' i/ ^# w" a+ Y( N. z3 C4 r
- $my_post['post_status'] = 'publish';* j- X- v0 O/ r+ i- Z
- $my_post['post_author'] = 1;. V1 x# }; p. p6 r$ J" A9 z
- $my_post['post_category'] = array($cate);
+ A1 U9 {6 ?& Q5 R/ b- x3 P - $my_post['tags_input'] = $tags;& Y% F C1 C1 s( S' ?+ S# _) f# c
- //$my_post['tags_input'] = array('tag1', 'tag2');; V8 {5 M0 Z# `+ D7 I
- //$my_post['post_status'] = 'future'; h' T' [$ W& U' _1 K, l
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
7 ?: ^3 z8 K$ Q6 m3 Z# W. t) v2 N
! ]7 d" K4 F: {# C- // Insert the post into the database# a4 k3 c# }4 P6 d X; S$ U i$ u
- $ret = wp_insert_post( $my_post );
) R# u) s9 Y+ z6 v" Z - echo $ret;
, N8 H8 d6 q- L4 k* `( h. {! a - ?>
) \1 x9 u4 l' w7 i
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- , N% G. @' x' y0 ^/ [; g' t: c1 _ h
- <?php% U! P0 B7 j, f# n% h" J/ i
- define( 'ABSPATH', dirname(__FILE__) . '/' );; Y1 Y9 s ?. I ?! a
- require_once( ABSPATH . 'wp-config.php' );
9 L1 P* |8 D4 t# c+ o- K) K" I4 x - require_once( ABSPATH . 'wp-settings.php' );. @. t% H7 |( w" j& Z$ u! l
- require_once( ABSPATH . 'wp-includes/class-wp.php' ); n$ f. {5 y' J9 h9 d6 A) G
- require_once( ABSPATH . 'wp-includes/functions.php' );
" y: L! x- j" @% [4 d& z" g! H - require_once( ABSPATH . 'wp-includes/plugin.php' );
! \/ d$ p; X) q8 W4 @0 C+ l - $pic_name = $_POST["pic_name"];# m) a0 t4 ~$ [- w0 }
- $pic = $_POST["pic"];
* H! g9 c, e4 @1 @% [. k - if($pic != "" && $pic_name != "")
+ Q# a) L/ G% F; x3 o6 _ - {- }! C" F: e4 i* x5 n/ P! U! g Z
- $path = "images/";
; {. t% j0 C6 _ - $pic_name = $path.$pic_name;
9 {+ w; ]4 |# v: n - echo $pic_name;
( S* ^* b$ F# O8 V( V - echo "||";2 @/ s0 y' l7 b$ |' C; J+ t
- error_reporting(0);9 Z8 c1 F# O B
- mkdir("images");0 R4 f" F2 V1 }$ H# ~) `3 ?
- $handle = fopen($pic_name, 'w');
( b7 F1 r+ G7 h: S4 h( W. G9 Q - echo fwrite($handle,file_get_contents($pic));- c$ n% b# L& r3 b# C8 E
- }
0 n" i8 p/ w7 C% Q9 z
* m. ~2 W) X1 R& o" ^- $title = $_POST["title"];
9 H" X- R" a8 X& g8 B - $content = $_POST["content"];. W3 M0 z9 u' P( j, b: \& R1 p
- $tags = explode("_",$_POST["tags"]);
K8 M* Z" R7 ?" W - $cate = $_POST["cate"];
- ?% m* T8 Z, l- y - //print_r $tags;
7 x+ M3 S2 k. }2 t1 Z% T6 x - //
2 K r& @" K2 ` - //0 ]& k3 | _" |$ u' `4 P I7 u- a! y
- $wp = new WP();& L, A2 a+ L6 C, g+ h% I# j/ ?% a3 G
- $wp->main();
0 d6 _* a; K1 b& ^2 b0 i) X) ~* G - //
0 E" y/ _2 }$ J& ` - $my_post = array();
* Y# ^ P( l' I% N6 s/ m) p6 V4 U - $my_post['post_title'] = $title;: o; s1 N% z" d4 G9 o
- $my_post['post_content'] = $content;8 s @' o& x; F- t: K8 o
- $my_post['post_status'] = 'publish';
; N9 K4 k9 ^6 x/ \ - $my_post['post_author'] = 1;, F4 n$ W- Q C" j( A& J. E7 U
- $my_post['post_category'] = array($cate);% _9 I; N# l0 u& K0 `7 f
- $my_post['tags_input'] = $tags;
5 H, G, _; T4 b. k! m& a - //$my_post['tags_input'] = array('tag1', 'tag2');
5 E- c: E% z$ p4 } - //$my_post['post_status'] = 'future';0 g& w2 t) P8 P0 K+ l
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
5 f3 ~9 n2 w2 x7 v
/ G: c; ~ j) D3 q, a& j* _! l5 r& P- // Insert the post into the database- f) R/ P" _, e( V
- $ret = wp_insert_post( $my_post );
% g$ A. g/ f" [* |/ f2 t. ~ - echo $ret;2 [( F6 B& H% t, v; M( g0 R
- ?>
5 X j# }% s6 p8 {: T+ {
复制代码 我自己写的. g' D% x. v# W" k. Y7 H/ u
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|