|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
: e' M- J" C$ i3 R7 E1 |! `- ~5 G/ o
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
' m# C0 P0 m' u" G! @4 k- u4 @. g/ i, Z
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了/ D* F. Q$ S3 }% w7 s3 A2 c! B
1 o- y# R- X x+ P# w8 t% j
方便实用 简单 何乐而不用呢
4 Q' G' q3 w! E W) i r- e- <?php; W, @; ~. g9 ], E- v, s5 n6 ~
8 e" I6 c% @; y* S! y- define( 'ABSPATH', dirname(__FILE__) . '/' );) z& p# r; `" Q
- require_once( ABSPATH . 'wp-config.php' );6 e% o2 g+ C) |; z* g* m
- require_once( ABSPATH . 'wp-settings.php' );
" T" m5 J; l+ [0 B I$ u - require_once( ABSPATH . 'wp-includes/class-wp.php' );( d0 j2 }) `8 V! A, Y) R
- require_once( ABSPATH . 'wp-includes/functions.php' );
# s5 n7 B Q% n# F# g) }! C% d) ^ - require_once( ABSPATH . 'wp-includes/plugin.php' );2 A0 x# e4 k+ Y4 f$ c
- $title = $_POST["title"];; y! X: Z$ L; _# z
- $content = $_POST["content"];( u' Q# \, o2 R0 D
- $tags = explode("_",$_POST["tags"]);8 \& j0 P% d4 ?$ K
- $cate = $_POST["cate"];% X/ q$ t% q0 W, w& S( A
- //print_r $tags;6 H- {3 f5 D$ U" W; L
- //
1 k: M7 Q1 M2 J6 X3 L) D5 g - //
1 p. _: a. c" L - $wp = new WP();
2 G2 l, d0 v1 H4 z* g - $wp->main();
$ T: d2 }, E- \' ^/ u# f9 u - //
9 V- U6 M* D& ]- s+ L. J4 ~8 j - $my_post = array();
1 m( C+ f& V$ Z6 H - $my_post['post_title'] = $title;; n S4 f8 ]% w
- $my_post['post_content'] = $content;* v8 w' I5 O \: J# s
- $my_post['post_status'] = 'publish';
. S4 r4 s- I0 ~8 h# m" n8 x - $my_post['post_author'] = 1;! x- K$ ~, d) j0 N2 @9 a% V, o
- $my_post['post_category'] = array($cate);
' d u. ~7 N: a( @! R6 r0 v0 j5 d7 Z1 l - $my_post['tags_input'] = $tags;: \# v% x1 \5 h( n
- //$my_post['tags_input'] = array('tag1', 'tag2');6 t; p! D) a4 g- z/ n
- //$my_post['post_status'] = 'future';
+ o0 _+ Z/ v) F5 P- w - ////$my_post['post_date'] = '2010-07-04 16:20:03';
v- c' t0 E* W! u ~, F, {
$ n2 }7 k2 ^- c( u- }* f1 n7 G1 g' t! B- // Insert the post into the database2 C+ v9 c5 M1 L% V L5 x
- $ret = wp_insert_post( $my_post );/ j5 O; G0 O/ `0 B$ M1 g
- echo $ret;5 X' N/ l4 f, K) z0 q1 i/ N
- ?>
! j: q" A' {3 y. t0 k) E! |
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
|) Z( X: C% q% _- <?php: ^& i2 E b, ~7 f
- define( 'ABSPATH', dirname(__FILE__) . '/' );
5 W7 p3 J; ?: W# O5 j. J$ B - require_once( ABSPATH . 'wp-config.php' );5 f' R8 H: q- R" M; }8 F9 {
- require_once( ABSPATH . 'wp-settings.php' );
$ l+ v+ ~$ Y5 U - require_once( ABSPATH . 'wp-includes/class-wp.php' );
7 U+ q% J h, g L% A - require_once( ABSPATH . 'wp-includes/functions.php' );
7 O& `& Q D2 {- K4 ~ - require_once( ABSPATH . 'wp-includes/plugin.php' );
4 o4 w: i$ x6 r( o: ^" V% P2 C - $pic_name = $_POST["pic_name"];" J& k5 y5 o! @1 L* e2 s8 g
- $pic = $_POST["pic"];4 s6 W: ^$ j/ h- ?5 w/ o8 N
- if($pic != "" && $pic_name != "")
9 Z5 n$ [% z3 n' O! R/ u - {
2 V3 K. D8 H0 m& N4 f) }5 [ - $path = "images/";
0 y/ u3 y9 u! L& b8 a7 | - $pic_name = $path.$pic_name;
) D# D$ K) ?9 s1 K# { - echo $pic_name;
2 h8 t' V7 Q8 k6 ~3 G6 R, n - echo "||";
Q1 R$ B' A% P$ U3 s5 H' L% B - error_reporting(0);! t8 H0 P4 z: h: @0 o
- mkdir("images");
0 a, K1 l5 r6 } - $handle = fopen($pic_name, 'w');
, j5 ^1 }) q* N6 @. v - echo fwrite($handle,file_get_contents($pic));) o. Q" G a- D' Y8 Y% {; h) V
- }
, J4 a9 H( s) N+ d - 0 M( s$ a7 I0 Q
- $title = $_POST["title"];
7 {" d U. B$ ^& v9 V - $content = $_POST["content"]; H* t1 N* `) ]; {% L0 d
- $tags = explode("_",$_POST["tags"]);* G& [: H% N6 a( e3 C; d
- $cate = $_POST["cate"];: a3 y7 T: P4 y5 q4 w6 t" r4 i
- //print_r $tags;/ @6 f! {- D0 ~0 V; e* q
- //
) k/ x7 W( g- [3 g& v" M - //) L" f, U) Y& {' y4 j
- $wp = new WP();" {+ E/ d% J$ g1 Y) F2 J5 i
- $wp->main();; A* W, u& c) ` g
- //
8 L' U5 H/ L3 w r - $my_post = array();
3 U; t2 l, B/ a6 C3 j! K( ~7 r - $my_post['post_title'] = $title;, Y# b( O" Q4 G% ^9 w5 v
- $my_post['post_content'] = $content;
' n5 X3 S1 n6 K7 F0 d& Q - $my_post['post_status'] = 'publish';- @7 O/ R3 c# L; D w; x8 o6 m
- $my_post['post_author'] = 1;. J* ?; _% {4 c, N
- $my_post['post_category'] = array($cate);/ b5 v. ?8 | M; s7 l5 S
- $my_post['tags_input'] = $tags;
3 a5 ~; h# |9 _* Z" _: O - //$my_post['tags_input'] = array('tag1', 'tag2');
: b+ H. n/ [) } - //$my_post['post_status'] = 'future';
* }: T3 T v' E0 w0 m - ////$my_post['post_date'] = '2010-07-04 16:20:03';2 W- x7 g, W' E, ^
- ) a( ^( T2 h' z U/ Y. B
- // Insert the post into the database
2 t9 j1 F$ |; B& z - $ret = wp_insert_post( $my_post );) @5 Z! j3 m; s* W" x0 l: u
- echo $ret;, g i9 P0 W9 a0 i5 F! x
- ?>
; K; I! }" {% v7 b Q6 r) e+ C, n
复制代码 我自己写的
2 h! B) Z8 @6 l9 m1 U; g+ d插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|