|
|
本帖最后由 finder 于 2014-12-28 15:13 编辑 2 X7 i+ c3 |) o' V
. Y/ O( b" K& m+ g% {
直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持
( W, ~( \" E4 u% h# P; _; S
1 G2 j8 p. s1 Y, `$ m' N. a: ]我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章 如果你采集的文章直接使用一个post操作就可以了9 p& u) E, F6 {
. z7 j7 _2 s7 v( b8 z( z9 @9 R: l2 r
方便实用 简单 何乐而不用呢
# M* F' l1 [+ r; H$ q- <?php# [- k' Q: x! s: @4 A5 o# R. K
/ g- L: J* l1 V0 ?- T6 z- define( 'ABSPATH', dirname(__FILE__) . '/' );6 `. H6 j: }" \" l* S5 d
- require_once( ABSPATH . 'wp-config.php' );; {; j' }% S5 @* ~
- require_once( ABSPATH . 'wp-settings.php' );% r1 { O r, _# ^* G
- require_once( ABSPATH . 'wp-includes/class-wp.php' );$ Q1 C( f3 y. C4 _; k
- require_once( ABSPATH . 'wp-includes/functions.php' );
& |+ |2 V) ~8 C6 H0 R5 f( ?0 E - require_once( ABSPATH . 'wp-includes/plugin.php' );
* C. ~+ Q+ U3 y' P - $title = $_POST["title"];7 T/ N$ R: w# ?
- $content = $_POST["content"];' a# Y$ D/ V3 J o3 w4 a
- $tags = explode("_",$_POST["tags"]);
' U6 z4 I% p0 w5 J% Q - $cate = $_POST["cate"];
% O/ z1 Z7 A5 q - //print_r $tags;1 d1 G( |9 W% \0 |+ t S |: a3 T
- //' {. z' k6 x6 I4 \ _ D+ U
- //
- D4 ~3 @$ Q2 j+ t; `+ u - $wp = new WP();0 ~5 ?! j( q. c# ~" k* ?
- $wp->main();
3 u8 y1 M3 U0 a5 m, ~) b - //6 U' e* `3 B/ J( |; O- o% H
- $my_post = array();
( K# `. s' l2 P4 l - $my_post['post_title'] = $title;
) l9 S4 p8 Z& `& J+ A$ W - $my_post['post_content'] = $content;
6 Z T& k- L, r2 {% B: n - $my_post['post_status'] = 'publish';$ A5 R8 S% Y! L7 m
- $my_post['post_author'] = 1;' ^1 u2 x4 ~$ ?4 }
- $my_post['post_category'] = array($cate);
7 | H: B5 q* H$ g/ }; K9 m, D3 r - $my_post['tags_input'] = $tags;
( v* j. ~1 A1 R( B1 R/ _2 n - //$my_post['tags_input'] = array('tag1', 'tag2');
6 |2 C+ Q& U8 [ - //$my_post['post_status'] = 'future';
% t% W" y, w# V# k* v - ////$my_post['post_date'] = '2010-07-04 16:20:03';
: r1 K" t1 {: k( d0 t5 g9 d7 M
& m, ~' N4 T+ R6 f- W( D: ]- // Insert the post into the database/ K' P N. ?5 c* V0 B: V
- $ret = wp_insert_post( $my_post );
* x5 V* |& f+ d9 @" s' J - echo $ret;. x5 \7 J |9 Z1 x! j) z
- ?>. c' p% g8 L3 N" m
复制代码 下面是更带更新图片版因为有些网站屏蔽了盗链接 小气- 0 X- g; n. U8 g
- <?php6 p: h9 z* ?6 P F
- define( 'ABSPATH', dirname(__FILE__) . '/' );% O" p! t8 e" N% t9 L9 H7 n1 A
- require_once( ABSPATH . 'wp-config.php' );
) H2 g1 G u" v* m' a - require_once( ABSPATH . 'wp-settings.php' );
! N, k% x ^% T, u: E4 a - require_once( ABSPATH . 'wp-includes/class-wp.php' );8 t8 V6 R' b( }* l" W
- require_once( ABSPATH . 'wp-includes/functions.php' );
: c6 Y/ M+ N& N - require_once( ABSPATH . 'wp-includes/plugin.php' );+ h; N) u( G. F; }, q' O) v* [$ w
- $pic_name = $_POST["pic_name"];
. ~. P, Y/ f4 _" i - $pic = $_POST["pic"];* Q6 K7 P. D, F8 v2 v
- if($pic != "" && $pic_name != "")
3 D3 F7 E# p' u, \: M3 t# E - {
0 s @0 l0 A3 g! q/ S - $path = "images/";2 P6 _. R/ G, L! K/ i7 ~
- $pic_name = $path.$pic_name;. {" [6 ]+ P6 U( {
- echo $pic_name;
6 c: w: \6 J9 ]* o) Y - echo "||";
6 ^/ o" w* m8 A e/ B& A - error_reporting(0);8 `$ n- T; R6 e, B# X5 R: d! |
- mkdir("images");
9 Q1 j" _- M$ P - $handle = fopen($pic_name, 'w');
/ [' g, C) P/ O; q" Y, A! Z - echo fwrite($handle,file_get_contents($pic));$ _! o+ j' l) p/ \" @& S0 d' B
- }( `8 g: u3 s; w2 y
' B. Z& h+ y, p- $title = $_POST["title"];
4 C: m4 t* T9 r- {9 {+ L7 ^ - $content = $_POST["content"];- B; _/ W. w2 z
- $tags = explode("_",$_POST["tags"]);/ o/ e! X; Y! H2 k, j6 M- b
- $cate = $_POST["cate"];
. |. d8 R" W! D8 Z2 T$ H - //print_r $tags;
A+ J2 r- _4 [: `0 ~ - //. |( [$ ~7 J/ ^
- //8 N0 @0 M( [% ]) y0 U* E
- $wp = new WP();4 t# Z- {9 D. S0 S2 @8 j5 \
- $wp->main();7 K8 g/ |" _; Z- o" [, \6 G, q
- //) E2 J: w% y2 i6 }- t/ u
- $my_post = array();( Q7 f& ^7 ]5 D
- $my_post['post_title'] = $title;" b' n X- b& ^
- $my_post['post_content'] = $content;
' D* B* c- t% i/ k4 l W# [$ a - $my_post['post_status'] = 'publish';
# b- F# V9 g: \& y - $my_post['post_author'] = 1;
3 S7 m- j, h- F# i2 n/ d - $my_post['post_category'] = array($cate);0 E6 Z% e' m1 ~+ G
- $my_post['tags_input'] = $tags;: S# y( z+ \! B6 r' ~, i
- //$my_post['tags_input'] = array('tag1', 'tag2');
) ^& {3 \0 m( R/ u, q - //$my_post['post_status'] = 'future';
/ X; c# `# t' Z2 l; t - ////$my_post['post_date'] = '2010-07-04 16:20:03';
! I$ l: S7 [ O+ C
K- D4 N- c- S8 J- // Insert the post into the database- [. X! _4 e; e, \
- $ret = wp_insert_post( $my_post );
* m i4 V3 q( f8 r3 F7 r1 f' M - echo $ret;
6 J2 T+ L0 j" o0 j" u1 L - ?>" g/ I- e: L. f6 X2 d
复制代码 我自己写的
' y5 X( g: i1 H4 O) X# K插入效果看图 不看广告看效果 已经测试过有需要的 拿去 |
评分
-
查看全部评分
|