|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
' Q) Y& g9 Z( p1 S: c
3 _, ]' T. X. d7 u ~# k) \/ ?直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
8 [/ ~6 @/ f9 Z) [
$ g9 S/ n: R; e8 R; C" S我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了 {8 w# o% `1 v ^
6 N5 e' b4 n: G' R2 k* l: e
方便实用 简单 何乐而不用呢
) v' ]8 S0 ?: x7 B# t% J% X# h- <?php( M# q! T- q7 y8 y* P9 T, c! g
: O2 {6 j; k( ~' `5 J9 d- define( 'ABSPATH', dirname(__FILE__) . '/' );
( f' ^, f$ C; w# W) B/ ]5 G, X& P4 Y - require_once( ABSPATH . 'wp-config.php' );
. c8 @- A# m3 {5 O - require_once( ABSPATH . 'wp-settings.php' );
?. l5 }* m0 U+ H$ X+ k - require_once( ABSPATH . 'wp-includes/class-wp.php' );! f: d/ g! `5 {! G2 v
- require_once( ABSPATH . 'wp-includes/functions.php' );$ c+ A& _8 c( L) }0 a8 U0 F
- require_once( ABSPATH . 'wp-includes/plugin.php' );
6 V6 ?" e6 p! C: I - $title = $_POST["title"];
* U, A% S* ]/ l - $content = $_POST["content"];
( B' j- I! I7 e+ e - $tags = explode("_",$_POST["tags"]);
8 ]6 A9 M4 g) q* }4 h+ ~ - $cate = $_POST["cate"];
( G# i. F2 G' L! ?; }2 e - //print_r $tags;- b1 Z# g, S; U8 _' R
- //
4 H1 }3 [. c, L e - //" Q, g0 \$ j+ y4 Z4 H
- $wp = new WP();- r4 H8 l# h3 U& y* B
- $wp->main();7 n4 N/ z7 @' c" G5 R% Y. b3 i* }
- //
v) `! f5 W/ ~6 q- e - $my_post = array();
% q( S/ K# P8 n Z: }( ^8 b - $my_post['post_title'] = $title;
4 \( Z+ ?* ]& Q4 m3 H! r, F' m - $my_post['post_content'] = $content;& E* z$ t8 a+ j! A6 Z
- $my_post['post_status'] = 'publish';' _3 z7 r3 n9 w8 l
- $my_post['post_author'] = 1;
' p& d9 i' y! S! W - $my_post['post_category'] = array($cate);5 G+ F& E' a0 ]* _& G" H
- $my_post['tags_input'] = $tags;
$ w1 F& x2 {9 |/ S - //$my_post['tags_input'] = array('tag1', 'tag2');" I1 L+ t, X' E6 _5 p" x
- //$my_post['post_status'] = 'future';3 ~7 @: z! w1 h, Z' n
- ////$my_post['post_date'] = '2010-07-04 16:20:03';8 l4 \1 D! e# j. b4 z
- 3 O$ c( o, N: c: J( ^
- // Insert the post into the database
9 q: ~1 M6 q( s; s/ | - $ret = wp_insert_post( $my_post );, M* }1 t/ E7 @% I" H
- echo $ret;
- U m6 N- e) g4 i - ?>6 t% [# g: C$ J
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
% ^6 C! D5 _/ A* X' X- <?php
! T$ I- z' [1 p' L( S$ |& [$ C6 n - define( 'ABSPATH', dirname(__FILE__) . '/' );- ^0 x+ A- f4 L" g% O3 _
- require_once( ABSPATH . 'wp-config.php' );
. j- `" L$ h8 s/ D% `% B - require_once( ABSPATH . 'wp-settings.php' );
1 f. }* z% p2 }6 k6 F2 K+ G$ A/ E7 ~ - require_once( ABSPATH . 'wp-includes/class-wp.php' );
& j. G+ M$ _1 y# w - require_once( ABSPATH . 'wp-includes/functions.php' );4 |: `& g% y3 Q3 ^! W# y
- require_once( ABSPATH . 'wp-includes/plugin.php' );
/ t6 W0 w) ?3 s4 T6 k - $pic_name = $_POST["pic_name"];7 N1 m0 u G- e7 J5 Q; s4 P5 H! j
- $pic = $_POST["pic"];
; K. p% m5 J) @- G+ \" q! a - if($pic != "" && $pic_name != "")' U) g3 a7 ]# V8 N% a! T) M R7 H
- {
' M; z: ?% [' f. k - $path = "images/";
7 z% `0 ]5 y8 m6 W& {7 p - $pic_name = $path.$pic_name; g4 S6 a; y: E& j
- echo $pic_name;
8 [& {7 Y/ w8 l% D) I/ _ - echo "||";% h) ~( T* w5 @0 n# A3 j
- error_reporting(0);
5 G3 K7 ^' j V( Y: G$ w0 p - mkdir("images");, l8 H, j( i) B! `* L: @! u
- $handle = fopen($pic_name, 'w');
( y% Z3 {6 x ?6 f3 m: h" ~ - echo fwrite($handle,file_get_contents($pic));
# M- U' T1 T- L- u- ^5 S - }
1 {6 k9 [9 S5 k/ N# F - 9 i7 G; d! B* c
- $title = $_POST["title"];8 D+ f* v. w5 G( Q+ B- o
- $content = $_POST["content"];
& D4 ]! w! g# F7 `- B - $tags = explode("_",$_POST["tags"]);
. s5 U. o7 z; k$ u. v) n/ P+ J a1 ` - $cate = $_POST["cate"];
4 P5 J. f# ^# s+ e# f - //print_r $tags;
; p' T* G5 [* O* B. S/ v9 H; X - //1 o! c2 S9 e) L5 ]) W8 C" |
- //
3 ^" T0 H0 o" C2 w' U. q! Q R - $wp = new WP();) q5 r: G7 a4 a9 v
- $wp->main();
" N5 f% J5 v$ F - //6 j6 N* H) }, B& o
- $my_post = array();
: K, s* T5 N. Q( _ - $my_post['post_title'] = $title;
6 C" C* b9 i) t* D0 f5 p5 ?* M. U' u - $my_post['post_content'] = $content;& q* R# a9 b$ I& ~( R- Q$ g
- $my_post['post_status'] = 'publish';
6 ?; n) t. k. J5 a) }$ a9 l3 N e - $my_post['post_author'] = 1; e" y- d. W$ _; O
- $my_post['post_category'] = array($cate);
; f( q. Q- b- C; A- D. m' Y - $my_post['tags_input'] = $tags;% Y; p7 l0 [, L, A, ~
- //$my_post['tags_input'] = array('tag1', 'tag2');
* D$ a' v# h1 s& D* Q) d! [ - //$my_post['post_status'] = 'future';! H8 t) O, Q Q1 f% t' }7 g
- ////$my_post['post_date'] = '2010-07-04 16:20:03';1 K6 J0 E6 [- d$ U- C
: X. K9 H: F7 n8 L, v x& T- // Insert the post into the database% M) N1 P w+ _0 c. Q
- $ret = wp_insert_post( $my_post );
: |: w ]& g+ e. R6 `: P/ M - echo $ret;
- }2 p. I; t3 I5 T4 n1 { - ?>
' i( Z1 Z2 h m( y- \- v
复制代码 我自己写的9 A0 S2 B( z/ I
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|