|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
0 u, {8 h* o5 p( c4 `
& w8 z3 f# S1 A1 N直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
l$ @( [3 F! \. U+ x! T
/ H4 o9 v( K5 y! a# s) k) V我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了( ~2 a' B! s# s- \+ V
6 K( R; n! _. ] c' p
方便实用 简单 何乐而不用呢
( b" o2 v* k+ [( y+ ?. G- <?php; B# s) S0 q6 K& ?2 q2 w
' I+ j: H. J6 h4 j, _- define( 'ABSPATH', dirname(__FILE__) . '/' );
% W. f% h$ r( R - require_once( ABSPATH . 'wp-config.php' );8 D9 V: [3 ?: |8 t3 k m1 C
- require_once( ABSPATH . 'wp-settings.php' );2 O3 z$ x4 w1 v2 J9 @% V0 C/ y
- require_once( ABSPATH . 'wp-includes/class-wp.php' );: B- [$ g/ t: c: P
- require_once( ABSPATH . 'wp-includes/functions.php' );0 _( ]4 k' Y6 r/ _5 K; O
- require_once( ABSPATH . 'wp-includes/plugin.php' );/ Y0 c9 \. I. Q9 @
- $title = $_POST["title"];
% ] P$ ~( H# T8 {( k& N$ z- } - $content = $_POST["content"];: D' f/ j: Y- u9 A' z6 t
- $tags = explode("_",$_POST["tags"]);* E' ~0 [% B1 m. e; t5 i9 ?& f7 m) p
- $cate = $_POST["cate"];
" q5 c9 R' h- K- C - //print_r $tags;
& [! C2 F' P; E - //3 I' G2 B2 k7 z7 f( P: `
- //- `& |& E6 z0 x9 U6 J1 {% x0 h% N1 i
- $wp = new WP();4 c# L2 w/ [( E- [, R# b! Z4 B
- $wp->main();
) I4 x+ W6 q: G1 j - //) W" b" g- E( h% R( g% i; V
- $my_post = array();
3 K) o& D$ \+ F, ] - $my_post['post_title'] = $title;
7 ?9 N; G2 n4 T& w* q2 y - $my_post['post_content'] = $content;/ a; O3 s& f- c" \$ E3 W
- $my_post['post_status'] = 'publish';
Z+ ?. w5 i. w8 V9 ~% j - $my_post['post_author'] = 1;
: _3 k2 r' C7 D0 z6 d) F/ Q - $my_post['post_category'] = array($cate);
" |# n. i, u9 }' D4 I; W( ]/ k8 N/ V* C - $my_post['tags_input'] = $tags;
& M6 ]8 ]' f( ^8 m! l - //$my_post['tags_input'] = array('tag1', 'tag2');
" b5 p0 u5 H5 S0 @ - //$my_post['post_status'] = 'future';# a9 J9 c5 O+ _, }8 `: h1 v
- ////$my_post['post_date'] = '2010-07-04 16:20:03';6 |7 X% T/ a7 ~6 N# p
- * A( {4 p9 g- C: [) Y* R# b& D% H
- // Insert the post into the database7 e2 @$ W* B* s, R
- $ret = wp_insert_post( $my_post );
$ l/ D# B3 k, L# c. O8 m! K - echo $ret;5 u6 `) u" |2 G, R# I
- ?>
. {/ q* L* u& |8 Y% z1 d
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 3 W- d/ I" k/ [3 ? P2 o
- <?php8 t- S8 A" `4 q8 Y. d
- define( 'ABSPATH', dirname(__FILE__) . '/' );
4 q- v4 c) m9 m: S5 A' d - require_once( ABSPATH . 'wp-config.php' );% k4 Z# t/ S! o2 Y! R8 }
- require_once( ABSPATH . 'wp-settings.php' );
" p+ ~% p* t4 L. b - require_once( ABSPATH . 'wp-includes/class-wp.php' );. [- m. r1 |2 L
- require_once( ABSPATH . 'wp-includes/functions.php' );$ h6 C& w9 M" q6 F5 X
- require_once( ABSPATH . 'wp-includes/plugin.php' );
) w/ } x3 v/ z - $pic_name = $_POST["pic_name"];
5 {1 p4 M9 a5 F9 C8 e! B - $pic = $_POST["pic"];
. S4 ^$ A$ D e5 s" m( B - if($pic != "" && $pic_name != "")
$ ]& l p9 @3 I, F" V$ i2 ?# E - {/ k; ?' R) N9 g- H0 {' i5 j7 I
- $path = "images/";
- l! P+ p' a1 F7 D( g/ | T - $pic_name = $path.$pic_name;# A1 _1 O/ r; y6 @& d
- echo $pic_name;9 L$ j; I# I" s; h/ x2 z
- echo "||"; u3 {0 o# V) K- }: M8 {1 R
- error_reporting(0);* q, T/ n4 v0 g: S0 ?3 i
- mkdir("images");
* J; S0 }& o6 p' A5 K - $handle = fopen($pic_name, 'w');; ?5 M, h1 S# e; q( V" y& j9 ?7 W7 M
- echo fwrite($handle,file_get_contents($pic));. P0 P; Y3 R, t$ Y9 t3 i9 b
- }4 H+ U' s, X+ k$ _" ], U. e
- 6 l, B7 e( Z" z6 W c0 n0 m
- $title = $_POST["title"];
6 `& w9 s' E/ \1 ]% ~1 S - $content = $_POST["content"];6 @# P' o: S2 x3 n+ [$ I6 w
- $tags = explode("_",$_POST["tags"]);% w5 u. I, ^( Z3 D$ Y' O
- $cate = $_POST["cate"];# t( m% E: a: Y3 E% X' T; Z2 F
- //print_r $tags;' B+ _7 K0 N o
- //
' w$ s5 B" H+ u& Z( b5 C; }' D( ^ - //
) v0 {6 X/ P0 P- E) e - $wp = new WP();, i: R9 l0 X; l% J) g+ y4 C1 B5 b
- $wp->main();# T, L0 Y' B& ^/ m$ S- @
- //! o% i2 _ w2 }" F! N
- $my_post = array();
' H9 F: j" U2 G" S9 w! Q - $my_post['post_title'] = $title;1 a9 j# M: i" G6 n
- $my_post['post_content'] = $content;
, o; W6 |: R" _2 S - $my_post['post_status'] = 'publish';
1 n7 D* k8 N: P1 e& h# W9 s4 ~ - $my_post['post_author'] = 1;% s# G& S# n* Z; \" x `: K& D) ?. Y# z
- $my_post['post_category'] = array($cate);
) H0 K; W/ u1 c4 h' ` - $my_post['tags_input'] = $tags;
) I D7 u+ y% j5 d4 j6 i - //$my_post['tags_input'] = array('tag1', 'tag2');
* i$ y7 ^$ C! p! P: h% ?5 l - //$my_post['post_status'] = 'future';; O! ~( Q' S; \2 D6 U* P" s
- ////$my_post['post_date'] = '2010-07-04 16:20:03';
1 f& P( j$ w5 @" ]
8 \& Y7 @' p" q+ p9 W* m8 ^6 x0 J- // Insert the post into the database
$ }$ i# X/ \: {: w- k! u6 y7 D1 U - $ret = wp_insert_post( $my_post );
, m; Y# q* a0 i - echo $ret;0 L) Y! y1 |' }
- ?>/ V+ C% o! i4 M: L+ K
复制代码 我自己写的
, Z8 t! `3 o4 }( C插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|