|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑
" n( K/ z, @7 d4 \7 w$ h, y! H0 @, v
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
7 G$ `2 b- [$ y# L! r: m* c) Z$ x3 s# e- k4 z1 [: ^
我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了6 i% s) X+ E$ W6 [6 P" E
, C ?" _! H1 U, u O" K! \
方便实用 简单 何乐而不用呢
& j( I4 X1 y! J7 p) n- <?php& m8 W, |9 y. G) o( y; g
- * E4 m N# c* Y: |9 h) I
- define( 'ABSPATH', dirname(__FILE__) . '/' );# a7 ^; `* ^0 E& ^ l: l d
- require_once( ABSPATH . 'wp-config.php' );
6 r1 ~, ~! V$ z/ h - require_once( ABSPATH . 'wp-settings.php' );
7 E+ {) D; T& i% m6 M - require_once( ABSPATH . 'wp-includes/class-wp.php' );* h5 k5 p, t6 e+ e4 Q9 I% T
- require_once( ABSPATH . 'wp-includes/functions.php' );
, B' [2 m- J4 y2 O; B2 G( x - require_once( ABSPATH . 'wp-includes/plugin.php' );
% [9 E' F9 C9 a0 G - $title = $_POST["title"]; g) c; `' N' }* R3 p, C8 x
- $content = $_POST["content"];% J( x9 P3 B+ m8 y- y" {
- $tags = explode("_",$_POST["tags"]);9 X: K& H6 _6 @! c5 e
- $cate = $_POST["cate"];2 v/ g' X7 [, V6 e) R8 G* ]0 w2 @5 `+ X9 p
- //print_r $tags;2 R' j* l9 I4 G
- //
0 d9 Y6 J7 f) |4 k# o$ c) H; { - //
0 [ [3 J2 X/ \& e* j0 W0 k& y - $wp = new WP();
8 e" z3 Z* ]; X. z w& p4 y - $wp->main();5 ]# k" |$ V4 D) b- `
- //. \0 F1 U3 @3 w. D" ]; V
- $my_post = array();
' C: e& n! s( c5 S3 o - $my_post['post_title'] = $title;# W V! `6 l2 ~4 b9 S' g. J) u/ J0 p3 u
- $my_post['post_content'] = $content; f3 ?! C3 A i5 G3 l
- $my_post['post_status'] = 'publish';7 c/ |6 L8 ?, W( P+ z% s9 B3 w; I
- $my_post['post_author'] = 1;- i9 ]4 H- B8 A
- $my_post['post_category'] = array($cate);6 g7 z. R0 a, g* Z5 R. @% I
- $my_post['tags_input'] = $tags;/ x5 j7 z7 ~" o9 f; f: o0 s
- //$my_post['tags_input'] = array('tag1', 'tag2');; I. a g( | X5 t2 z" \% m
- //$my_post['post_status'] = 'future';+ ?% x2 J! q7 r5 s/ T
- ////$my_post['post_date'] = '2010-07-04 16:20:03';/ t1 u9 p! C2 c) g; E
& e( j ^9 `+ j$ z$ u$ {- // Insert the post into the database8 q& N- i" O* t; z M3 o
- $ret = wp_insert_post( $my_post );
0 d) ~- J$ S- [, y4 ] - echo $ret;
2 k8 y7 ~8 C2 C) U, ^! O" {) U' J - ?>
4 n( y6 J* O* J/ I4 a! X( V
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
& Q! z5 z6 q# f9 n! j+ C- <?php2 I: v1 F3 S0 B7 v2 P! }$ M
- define( 'ABSPATH', dirname(__FILE__) . '/' ); w* ^: G5 G/ Q: Q+ d$ f2 x; o
- require_once( ABSPATH . 'wp-config.php' );
9 O3 k6 ^# \' P& J" E. o' J - require_once( ABSPATH . 'wp-settings.php' );
5 a1 R- D; g( m - require_once( ABSPATH . 'wp-includes/class-wp.php' );
" _6 Z6 W' w+ _0 H - require_once( ABSPATH . 'wp-includes/functions.php' );
/ M7 m) T* n5 S$ d! z! K7 V - require_once( ABSPATH . 'wp-includes/plugin.php' );
( C. O) c" v; t6 y6 W$ e0 k - $pic_name = $_POST["pic_name"];, ?% a3 ?" B. `9 f0 k6 t$ s
- $pic = $_POST["pic"];9 f9 l( X4 W. _$ ~, q4 W) H% T
- if($pic != "" && $pic_name != "")
% X8 N5 d/ s4 @4 Z! s1 B* v - {: j" F+ \# t" z# i% x' a: n# f
- $path = "images/";
9 p+ D4 V9 h+ n, l% g! D - $pic_name = $path.$pic_name;
4 m2 ?( Z; J0 W9 m3 o- O( G9 ~ - echo $pic_name;. o& h6 u W& }& O, u/ g8 D0 T; e& Y
- echo "||";' {' Y7 ], F1 h
- error_reporting(0);
3 r8 l' E' R* } - mkdir("images");
1 n# {7 G( n% i% C, E$ F( ~5 u - $handle = fopen($pic_name, 'w');6 k7 x! s$ a9 q3 c0 ~4 y$ U
- echo fwrite($handle,file_get_contents($pic));
9 B% |8 n+ n% Y/ W! M7 _ - }
& ?) x, S4 ]% ~
. l0 D) A- Z6 Y8 s- $title = $_POST["title"];9 r! @5 E& T9 H) g
- $content = $_POST["content"];, ?/ u/ ]# |* d. O1 `
- $tags = explode("_",$_POST["tags"]);: {) r$ C( L0 g
- $cate = $_POST["cate"];6 c* x7 i3 o4 _7 b3 r0 M! H/ d- a
- //print_r $tags;% @! k" Z+ O9 |3 p- ]- g$ x$ e
- //
7 C* d( E( J4 }* f - //; I2 s1 N: `) s3 \
- $wp = new WP();) ?7 P4 S3 m2 a$ _0 w
- $wp->main();
0 V; u% C. T7 a0 F9 a6 T, F, x E - //
2 M' N( b) V" _: r! \) B( p$ F - $my_post = array();) o+ k: x: u% N
- $my_post['post_title'] = $title;8 m6 ?+ X( n5 [& m8 \
- $my_post['post_content'] = $content;6 l( W; P. y' X; X7 p
- $my_post['post_status'] = 'publish';# ]' \+ Y: G: F4 Y: z" m7 b1 X7 y
- $my_post['post_author'] = 1;4 [% r. z" z' J- }
- $my_post['post_category'] = array($cate);/ s- J/ f. Q- i: ^0 N5 j1 N5 X
- $my_post['tags_input'] = $tags;
8 h5 q. l U6 E! U% ]( ^ n - //$my_post['tags_input'] = array('tag1', 'tag2');# C, Y- [( O. a3 V! q0 F! `
- //$my_post['post_status'] = 'future';
) W2 f* g+ t& \ - ////$my_post['post_date'] = '2010-07-04 16:20:03';
/ Z" J9 {3 `9 t0 A
) j7 \# F- f2 h: c, K- Y9 I- // Insert the post into the database
D. W4 h: i# Q n2 H5 Q6 C; c - $ret = wp_insert_post( $my_post );
# p. B) e1 X- ?* ]0 X8 W8 }/ a - echo $ret; N3 `+ Q3 I# y% X% T
- ?>
' Y% y( `* o t# p, X, o
复制代码 我自己写的
6 o2 z* J$ n& E$ {# w插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|