|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 + L, O% O4 S, n8 S- k+ I! J
2 ]7 {% F3 |2 F" @" O8 d# X
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
6 P4 I" L: [2 O7 I& v' h! Y
, {4 p6 B: M/ G: ^/ S* x我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了0 t. M5 s3 M3 S3 C" {% X
4 g- P3 i5 `' c: I4 N方便实用 简单 何乐而不用呢- 5 _) l) a6 W& |% l
- <?php. ?# H6 `9 w0 L# f7 P
- 3 b/ h7 F3 T3 s1 W, K0 J+ r# z( o
- define( 'ABSPATH', dirname(__FILE__) . '/' );$ N b M, Z- C6 d
- require_once( ABSPATH . 'wp-config.php' );# U8 i" p8 z1 w& e' y8 D2 I
- require_once( ABSPATH . 'wp-settings.php' );7 _ Q# L6 C. ^7 n1 ^
- require_once( ABSPATH . 'wp-includes/class-wp.php' );
0 E" g. j6 a' g L# ? - require_once( ABSPATH . 'wp-includes/functions.php' );
- P/ I/ l: \" e - require_once( ABSPATH . 'wp-includes/plugin.php' );
" ^, x K* A* p+ j - $title = $_POST["title"];
( c G9 u4 W/ n& c! G - $content = $_POST["content"];+ T) K. n2 E* d8 R7 D# z& b y5 o
- $tags = explode("_",$_POST["tags"]);
4 m+ F0 m; e( o# W - $cate = $_POST["cate"];
& m& j" O0 }( l8 M+ b ^8 ]3 ^ - //print_r $tags;
5 e- s0 m& H$ v/ J - //
: M5 o$ T/ i7 o' g$ p2 K* T - //, c& }/ f( }4 B: q% n& v
- $wp = new WP();& H- V) Q/ B) C: X) b: L
- $wp->main();) m9 }$ ^: {% v5 o
- //( z% g5 D% l! O1 i8 Z: @2 ?
- $my_post = array();
3 ^. ^- M, j/ _ - $my_post['post_title'] = $title;
+ y4 a# x" o s" H, d - $my_post['post_content'] = $content;* F1 |- T% c( p. A- E4 e. g M P
- $my_post['post_status'] = 'publish';, }* Z9 s/ v/ \4 D
- $my_post['post_author'] = 1;$ ?- ~5 A5 t4 w2 h- L3 B3 v
- $my_post['post_category'] = array($cate);# @ @, d w1 Y5 e0 c7 V
- $my_post['tags_input'] = $tags;
# t4 i9 z$ k1 j- S! ^( ^ - //$my_post['tags_input'] = array('tag1', 'tag2');" A' f+ A2 L8 n$ y6 F3 G6 Q9 P
- //$my_post['post_status'] = 'future';
, o8 i9 ~5 U g - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: _! A: N9 m L- y$ q) p
, U& h& t A$ ~4 q# t9 \7 o- // Insert the post into the database; g. M9 H2 z* N% W7 I5 _* m6 t- f
- $ret = wp_insert_post( $my_post );
/ v( e# v; }) ?' B" j! \ - echo $ret;
2 ^5 b; H8 r+ \2 w( p' K - ?>
5 n1 Y" s% z8 g/ d. e3 ^1 B
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
5 f8 X) U1 a$ J$ I- <?php
3 y6 r0 l ^( \) v( B5 Y; x9 V+ U - define( 'ABSPATH', dirname(__FILE__) . '/' );
0 ~, M6 Q$ I5 f) n% m5 { - require_once( ABSPATH . 'wp-config.php' );" o A# J3 o% u1 L* w: {
- require_once( ABSPATH . 'wp-settings.php' );
y2 S. N$ h8 J: J- p' l8 c" h. Z$ T - require_once( ABSPATH . 'wp-includes/class-wp.php' );- E0 V9 `+ {+ O# ]
- require_once( ABSPATH . 'wp-includes/functions.php' );
& ~- I( V$ _9 T - require_once( ABSPATH . 'wp-includes/plugin.php' );/ B8 h3 I5 u C
- $pic_name = $_POST["pic_name"];
6 E7 q+ z1 Z1 r) Z W, A# e# ~$ o1 c4 | - $pic = $_POST["pic"];7 u& j" X1 j0 H' a! [+ z8 C: i
- if($pic != "" && $pic_name != "")# E& T) M K: [- S5 V6 o& w( f
- {
6 B9 {- z( |) }9 ?% x - $path = "images/";
# U i/ {/ C* z - $pic_name = $path.$pic_name;5 _/ Y, d% C2 f. [! G& R
- echo $pic_name;# ^9 _. r2 \- ]& ]2 O+ H
- echo "||";
e( f: ?$ A5 f j+ U/ } - error_reporting(0);
: @0 m0 |% t- K3 m1 O2 D' J" g - mkdir("images");
' R, I- W5 c o - $handle = fopen($pic_name, 'w');
, y1 n, S+ p/ l' U/ S; O - echo fwrite($handle,file_get_contents($pic));
- H" @& v2 }" { - }
7 \& }- o3 R" P2 v* A
# d4 j' c4 A% d- c; a0 y0 s. `- $title = $_POST["title"];/ ^" y/ O# _+ x6 `
- $content = $_POST["content"];4 U/ L6 T) z F- r8 `0 y
- $tags = explode("_",$_POST["tags"]);" @$ X3 i/ P7 i* N# Y
- $cate = $_POST["cate"];
; b# ] U; ~+ E' s - //print_r $tags;& R# A* v2 ?% X2 w2 _2 }' q
- //
d) t6 s4 W N, S2 ?8 O' V - //
C6 ]* h7 F3 n T) l" P - $wp = new WP();) b0 c j8 x8 `' X+ e
- $wp->main();) l( N9 `% C: I* y
- //$ S3 i/ u- `* ]/ J* v; S
- $my_post = array();
; Z( b6 o7 V2 c2 G& h - $my_post['post_title'] = $title;7 {/ c; A) [9 h0 } H. H9 s
- $my_post['post_content'] = $content;
3 q+ d& o/ w. A% |) c7 _0 P( w - $my_post['post_status'] = 'publish';
1 f8 p6 L9 ~% p/ } - $my_post['post_author'] = 1;
* w2 O7 d# W3 [3 H8 _% o - $my_post['post_category'] = array($cate);( J- }% e2 @- |* G& ^% N( u
- $my_post['tags_input'] = $tags;
6 n; {& x0 Q1 ^) K8 J C/ @2 } - //$my_post['tags_input'] = array('tag1', 'tag2');/ f$ F8 K" q. b* G6 m: }
- //$my_post['post_status'] = 'future';
4 y$ ?. i2 P; E* ^' Z - ////$my_post['post_date'] = '2010-07-04 16:20:03';2 k3 ~- @7 E& t1 O' f/ E; x# X2 @+ @
4 [4 M' z2 w- ^$ J3 R% F v- // Insert the post into the database& v1 \1 @, O# a4 U
- $ret = wp_insert_post( $my_post );
7 y& q7 o( E/ ?2 b9 A M& O - echo $ret;8 ^9 o0 V8 r1 W7 B" K( V3 o1 u
- ?>$ ^- H) S* ~7 y V8 K
复制代码 我自己写的/ h. q M: J8 S, D' Y1 T! ^) F
插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|